{"id":19483951,"url":"https://github.com/google-developers-sohag/simplerecyclerviewapp","last_synced_at":"2026-04-20T04:03:32.463Z","repository":{"id":92145021,"uuid":"471128499","full_name":"Google-Developers-Sohag/SimpleRecyclerViewApp","owner":"Google-Developers-Sohag","description":"RecyclerView Application example using kotlin and viewbinding.","archived":false,"fork":false,"pushed_at":"2022-03-28T07:27:37.000Z","size":387,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-25T17:47:43.763Z","etag":null,"topics":["android","koltin-android","recyclerview","recyclerview-adapter","view-binding"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Google-Developers-Sohag.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-17T20:13:44.000Z","updated_at":"2022-03-28T07:25:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"a1f4f276-6c74-42e7-8b1d-51a575d23464","html_url":"https://github.com/Google-Developers-Sohag/SimpleRecyclerViewApp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Google-Developers-Sohag/SimpleRecyclerViewApp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Google-Developers-Sohag%2FSimpleRecyclerViewApp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Google-Developers-Sohag%2FSimpleRecyclerViewApp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Google-Developers-Sohag%2FSimpleRecyclerViewApp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Google-Developers-Sohag%2FSimpleRecyclerViewApp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Google-Developers-Sohag","download_url":"https://codeload.github.com/Google-Developers-Sohag/SimpleRecyclerViewApp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Google-Developers-Sohag%2FSimpleRecyclerViewApp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279001649,"owners_count":26083147,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","koltin-android","recyclerview","recyclerview-adapter","view-binding"],"created_at":"2024-11-10T20:18:43.082Z","updated_at":"2025-10-09T15:43:23.386Z","avatar_url":"https://github.com/Google-Developers-Sohag.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SimpleRecyclerViewApp\n\nShows how to display some items in a simple list using the `RecyclerView` and `RecycleView.Adapter`.\n\nThe `RecycleView` is the entity that displays the list to the user on the layout of your Ui. \u003c/br\u003e\nThe `RecyclerView.Adapter\u003cT\u003e` is the entity that adapts and manipulates to the recycler to be displayed on the user interface later when\nrendering the android view, it also updates the data with their respective views. \u003c/br\u003e\n\n## Prepare your Ui : \n- Create a MainActivity class :\n```kt\npackage com.example.session2\n\nimport android.content.Intent\nimport android.os.Bundle\nimport androidx.appcompat.app.AppCompatActivity\n\nclass MainActivity : AppCompatActivity() {\n    override fun onCreate(savedInstanceState: Bundle?) {\n        super.onCreate(savedInstanceState)\n    }\n}\n```\n- Define the activity inside the `AndroidManifest.xml` :\n```xml\n\u003cactivity\n  android:name=\".MainActivity\"\n  android:exported=\"true\"\u003e\n\u003c/activity\u003e\n```\n- Define an Action main intent filter with a launcher category (build a launcher activity when the user clicks the app icon in the \napp drawer) :\n```xml\n\u003cactivity\n  android:name=\".MainActivity\"\n  android:exported=\"true\"\u003e\n    \u003cintent-filter\u003e\n      \u003caction android:name=\"android.intent.action.MAIN\" /\u003e\n\n      \u003ccategory android:name=\"android.intent.category.LAUNCHER\" /\u003e\n  \u003c/intent-filter\u003e\n\u003c/activity\u003e\n```\n- Define the binding framework from the jetpack compose (shortcut to accessing views with their IDs directly and their root easily) :\n**In app/gradle.build android block :**\n```groovy\nandroid {\n    ...\n    buildFeatures {\n        viewBinding true\n    }\n}\n```\n- Naviagte to `app/src/main/res/layout/activity_main.xml` and add the context to the root layout : \n```xml\ntools:context=\".MainActivity\"\n```\n- Add a recyclerview to your xml file with an id.\n- The final `activity_main.xml` file should look like that :\n```xml\n\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\u003cLinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    xmlns:tools=\"http://schemas.android.com/tools\"\n    android:layout_width=\"match_parent\"\n    android:layout_height=\"match_parent\"\n    android:orientation=\"vertical\"\n    tools:context=\".MainActivity\"\u003e\n\n    \u003candroidx.recyclerview.widget.RecyclerView\n        android:id=\"@+id/recycler\"\n        android:layout_width=\"match_parent\"\n        android:layout_height=\"match_parent\"\n        tools:listitem=\"@layout/item_model\" /\u003e\n\u003c/LinearLayout\u003e\n```\n- Navigate to the `onCreate(onSavedInstance: Bundle)` method, and set your xml file using `setContentView()` and the inflated layout : \n```kotlin\nbinding = ActivityMainBinding.inflate(layoutInflater)\nsetContentView(binding.root)\n```\n- Now a `RecyclerView` instance is predefined and the ready to be accessed using its binding reference which returns a recycler view instance.\n- Now setup your recycler `LayoutManager` and `Adapter`.\n- `LayoutManager` : controls how the items are getting viewed to the user (Linear or Grid).\n- `RecyclerView.Adapter` : holds the data to be adapted later on the user interface.\n- The `RecyclerView.Adapter` accepts an array of any type as a parameter -- the array is the data that would be adapted onto the ui later when\ninstantiating the android view.\n- The `LayoutManager` can be a `LinearLayoutManager` for displaying items underneath each other, or `GridLayoutManager` for displaying items in \na grid fashion.\n- The final setup so far : \n```kt\nclass MainActivity : AppCompatActivity() {\n    \n    private lateinit var binding: ActivityMainBinding\n    \n    override fun onCreate(savedInstanceState: Bundle?) {\n        super.onCreate(savedInstanceState)\n        \n        binding = ActivityMainBinding.inflate(layoutInflater)\n        setContentView(binding.root)\n        supportActionBar?.title = \"First App\"\n        \n        val array = ArrayList\u003cItemModel\u003e()\n        array.add(ItemModel(R.drawable.ic_launcher_background, \"Ahmed\"))\n        array.add(ItemModel(R.drawable.ic_launcher_background, \"Abdo\"))\n        array.add(ItemModel(R.drawable.ic_launcher_background, \"Eman\"))\n        \n        val adapter = Adapter(array)\n        binding.recycler.layoutManager = LinearLayoutManager(this)\n        binding.recycler.adapter = adapter\n    }\n}\n```\n## Bind data to the Ui : \n- Create a DataModel class and this class would hold the data for each position to be rendered on its respective android views : \n```kt\ndata class ItemModel(val photo: Int, val name: String)\n```\n- Create a `RecyclerView.ViewHolder` that holds the definition of each children views on each position with the recycler list :\n```kt\nimport androidx.recyclerview.widget.RecyclerView\n\nclass ViewHolder(binding: ItemModelBinding) : RecyclerView.ViewHolder(binding.root) {\n        val photo = binding.image\n        val name = binding.textView\n}\n```\n\n- Create a `RecyclerView.Adapter` that would return an instance of a ViewHolder and adapters data onto the children views on each position : \n```kt\nimport android.view.LayoutInflater\nimport android.view.ViewGroup\nimport android.widget.Toast\nimport androidx.recyclerview.widget.RecyclerView\nimport com.example.session2.databinding.ItemModelBinding\n\nclass Adapter(private val list: ArrayList\u003cItemModel\u003e) : RecyclerView.Adapter\u003cAdapter.ViewHolder\u003e() {\n\n    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {\n        val inflatedView = ItemModelBinding.inflate(LayoutInflater.from(parent.context))\n        return ViewHolder(inflatedView, parent, false))\n    }\n\n    override fun onBindViewHolder(holder: ViewHolder, position: Int) {\n        val item = list[position]\n        holder.name.text = item.name\n        holder.photo.setOnClickListener {\n            Toast.makeText(it.context, position.toString(), Toast.LENGTH_SHORT).show()\n        }\n    }\n\n    override fun getItemCount(): Int {\n        return list.size\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogle-developers-sohag%2Fsimplerecyclerviewapp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoogle-developers-sohag%2Fsimplerecyclerviewapp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoogle-developers-sohag%2Fsimplerecyclerviewapp/lists"}