{"id":19635798,"url":"https://github.com/codepath/fb-recyclerview-demo","last_synced_at":"2025-04-28T08:31:03.067Z","repository":{"id":36077002,"uuid":"40376873","full_name":"codepath/fb-recyclerview-demo","owner":"codepath","description":"Proposed RecyclerView Demo changes","archived":false,"fork":false,"pushed_at":"2018-05-25T19:52:38.000Z","size":879,"stargazers_count":8,"open_issues_count":0,"forks_count":9,"subscribers_count":14,"default_branch":"master","last_synced_at":"2023-05-10T14:13:28.404Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codepath.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-08-07T19:14:15.000Z","updated_at":"2023-02-14T12:54:45.000Z","dependencies_parsed_at":"2022-09-03T00:11:07.514Z","dependency_job_id":null,"html_url":"https://github.com/codepath/fb-recyclerview-demo","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codepath%2Ffb-recyclerview-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codepath%2Ffb-recyclerview-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codepath%2Ffb-recyclerview-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codepath%2Ffb-recyclerview-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codepath","download_url":"https://codeload.github.com/codepath/fb-recyclerview-demo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224102180,"owners_count":17256108,"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","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":[],"created_at":"2024-11-11T12:27:04.657Z","updated_at":"2024-11-11T12:27:05.514Z","avatar_url":"https://github.com/codepath.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RecyclerView Demo\nThis is a simple contacts app to demonstrate how to display a list of objects using a `RecyclerView`.\n\n![completed contact app](images/recycler_view_demo_completed.gif)\n\n## Contact Model\nAsk students to copy the following `Contact` model:\n\n```\npublic class Contact {\n    private String mName;\n    private boolean mOnline;\n\n    public Contact(String name, boolean online) {\n        mName = name;\n        mOnline = online;\n    }\n\n    public String getName() {\n        return mName;\n    }\n\n    public boolean isOnline() {\n        return mOnline;\n    }\n\n    private static int lastContactId = 0;\n\n    public static List\u003cContact\u003e createContactsList(int numContacts) {\n        List\u003cContact\u003e contacts = new ArrayList\u003c\u003e();\n\n        for (int i = 1; i \u003c= numContacts; i++) {\n            contacts.add(new Contact(\"Person \" + ++lastContactId, i \u003c= numContacts / 2));\n        }\n\n        return contacts;\n    }\n}\n```\n\n## Key Demonstration Points\n\n### Recycled items\nWithout re-enabling the button on each call to `onBindViewHolder`, the button will retain the state from the last contact that was displayed in its `ViewHolder`.\n\nThis can be demonstrated by scrolling to the bottom of the list and back up.  Enabled buttons at the top of the list will now be disabled.\n\n```java\n    // In Contact.java\n\n    @Override\n    public void onBindViewHolder(ViewHolder viewHolder, int position) {\n        Contact contact = mContacts.get(position);\n\n        TextView textView = viewHolder.nameTextView;\n        textView.setText(contact.getName());\n\n        Button button = viewHolder.messageButton;\n\n        if (contact.isOnline()) {\n            button.setText(\"Message\");\n\n            // OMIT to show that rows are recycled.\n            //\n            // Scrolling past the midpoint of the list (when contacts are listed as offline)\n            // and scrolling back up should result in some buttons being inadvertently disabled.\n            button.setEnabled(true);\n        }\n        else {\n            button.setText(\"Offline\");\n            button.setEnabled(false);\n        }\n    }\n```\n\n![completed contact app](images/recycler_view_demo_recycled_items.gif)\n\n### Notifying the adapter that the UI must be updated due to dataset changes\nWithout the call to `notifyItemRangeInserted`, the UI will not reflect the additional contacts that have been appended to the contact list.\n\n```java\n    // In Contact.java\n\n    public void addMoreContacts(List\u003cContact\u003e newContacts) {\n        int insertionPosition = mContacts.size();\n        mContacts.addAll(newContacts);\n\n        // OMIT to illustrate how the UI is independent from the dataset\n        // and does not update automatically.\n        notifyItemRangeInserted(insertionPosition, newContacts.size());\n    }\n```\n\n![stale UI](images/recycler_view_demo_stale_ui.gif)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodepath%2Ffb-recyclerview-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodepath%2Ffb-recyclerview-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodepath%2Ffb-recyclerview-demo/lists"}