{"id":18389319,"url":"https://github.com/rightpoint/universaladapter","last_synced_at":"2025-04-07T02:34:17.009Z","repository":{"id":29398807,"uuid":"32934104","full_name":"Rightpoint/UniversalAdapter","owner":"Rightpoint","description":"A single adapter implementation for any scrolling view or ViewGroup.","archived":false,"fork":false,"pushed_at":"2016-03-01T20:07:20.000Z","size":2054,"stargazers_count":53,"open_issues_count":1,"forks_count":6,"subscribers_count":27,"default_branch":"master","last_synced_at":"2025-03-22T11:43:17.853Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Rightpoint.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}},"created_at":"2015-03-26T15:02:34.000Z","updated_at":"2021-09-01T10:37:33.000Z","dependencies_parsed_at":"2022-09-06T17:01:15.311Z","dependency_job_id":null,"html_url":"https://github.com/Rightpoint/UniversalAdapter","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rightpoint%2FUniversalAdapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rightpoint%2FUniversalAdapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rightpoint%2FUniversalAdapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rightpoint%2FUniversalAdapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Rightpoint","download_url":"https://codeload.github.com/Rightpoint/UniversalAdapter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247583311,"owners_count":20962013,"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-06T01:42:35.119Z","updated_at":"2025-04-07T02:34:12.001Z","avatar_url":"https://github.com/Rightpoint.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# UniversalAdapter\n\n[![Raizlabs Repository](http://img.shields.io/badge/Raizlabs%20Repository-2.2.0-blue.svg?style=flat)](https://github.com/Raizlabs/maven-releases)\n\nA single adapter implementation for any scrolling view or `ViewGroup`.\n\nThis library consolidates the differences between `BaseAdapter`, `RecyclerView.Adapter`, `PagerAdapter`, and binding to `ViewGroup` into one unified API.\n\nIts underlying implementation is based on the `ViewHolder` pattern and abstracts it to work with all of the adapter views.\n\n## Including in your project\n\n### Gradle\n\nBy standard Gradle use:\n\n```\n  dependencies {\n    compile 'com.raizlabs:UniversalAdapter:2.2.0'\n  }\n```\n\n\n## Usage\n\nThis library comes packed with some notable features:\n  1. One adapter implementation to rule them all. Enforces `ViewHolder` pattern and binds to a\n  range of `ViewGroup` such as `LinearLayout`, `GridView`, `ListView`, `RecyclerView`,\n  `ViewPager`, and more!\n  2. List observability: when an adapter's inner content changes, notifications to the parent adapter view happen automatically\n  3. Merged adapter: add an arbitrary amount of `UniversalAdapter`'s together to enable diverse view-data sets!\n  4. Unified header and footer support: add an arbitrary number of headers and footers to any `UniversalAdapter` and let the library handle it for you, no matter the parent view!\n\n\n### Adapters\n\nThis library comes with two main adapter classes: `UniversalAdapter` and `ListBasedAdapter`.\n\n`UniversalAdapter`: The base class that all adapters should derive from. It's strongly\nbased on the `BaseAdapter` class, while not relying on subclassing it.\n\n`ListBasedAdapter` supports a `List` of items. _Note: use ObservableListWrapper to pass changes from this list to this adapter automatically!_\n\n#### How Binding Works\n\nAny `UniversalAdapter` can bind to the `ViewGroup` you need it to by using the `UniversalConverterFactory`, which exposes a `UniversalConverter` class. Depending on the parent `ViewGroup` passed to `UniversalConverterFactory.create()`, it returns the appropriate adapter implementation.\n\nThe `UniversalConverter` provides methods for:\n  1. Clicks on items, footers, and headers\n  2. Long Clicks on items, footers, and headers\n  3. Swapping in another adapter.\n  4. Retrieving the contained adapter\n  5. And more\n\n#### Example\n\nTo define an adapter:\n\n```java\n\n\nListBasedAdapter\u003cItem, Holder\u003e adapter = new ListBasedAdapter\u003c\u003e() {\n  @Override\n  protected void onBindViewHolder(Holder viewHolder, Item item, int position) {\n    // bind here\n  }\n\n  @Override\n  protected Holder onCreateViewHolder(ViewGroup parent, int itemType) {\n      return new Holder(inflateView(parent, R.layout.my_layout));\n  }\n\n}\n\n\n```\n\nTo add items to this list-based adapter:\n\n\n```java\n\nadapter.loadItemsList(myItems);\nadapter.add(item);\n\n\n```\n\nNow to connect it to a `ListView`, `RecyclerView`, `ViewPager`, or `ViewGroup`:\n\n```java\n\nUniversalConverter\u003cItem, Holder\u003e universalConverter = UniversalConverterFactory.create(adapter, someViewGroup);\n\n// each UniversalConverter determines how the click events works\n// you just worry about the callback!\nuniversalConverter.setItemClickedListener(new ItemClickedListener\u003c\u003e() {\n\n  @Override\n  public void onItemClicked(UniversalAdapter\u003cItem, Holder\u003e adapter, Item item, Holder holder, int position) {\n    // do something here\n  }\n\n})\n\n```\n\nThis method \"converts\" the `UniversalAdapter` to the appropriate adapter for the `ViewGroup` passed. If it cannot find a more specific adapter, it utilizes a `ViewGroupAdapter`, which adds all views from the adapter to a `ViewGroup`.\n\n### Merged Adapter\n\nEver need multiple kinds of uniform adapter data and want to display them together?\n\nA `MergedUniversalAdapter` allows you to add multiple `UniversalAdapter` and display them all together!\n\n```java\n\nMergedUniversalAdapter merged = new MergedUniversalAdapter();\nmerged.addAdapter(listAdapter);\nmerged.addAdapter(anotherAdapter);\n\n// bind the adapter to the ViewGroup you want to use.\nUniversalConverterFactory.create(merged, viewGroup);\n\n```\n\n### Header and Footers\n\nOne of the pain points of `RecyclerView` is that it does _not_ natively support header and footer views. `ListView` does provide a mechanism, but this is not done uniformly at the adapter level. We added header and footer support to `UniversalAdapter` to merge the two concepts together at the `Adapter` level, so no matter the parent container, it works the same way.\n\nTo use it:\n\n```java\n\nListBasedAdapter\u003cItem, Holder adapter = new ListBasedAdapter\u003c\u003e();\n\n// add items you want to display\nadapter.loadItemList(someList);\n\n// now we want some headers, no problem!\nadapter.addHeaderView(myHeaderView);\n\n// we can also add ViewHolders too!\nadapter.addHeaderHolder(myViewHolder);\n\n// same for footers\nadapter.addFooterView(myFooter);\nadapter.addFooterHolder(myFooterHolder);\n\n// bind to ViewGroup of your choice:\nUniversalConverterFactory.create(adapter, viewGroup);\n\n```\n\nPlease _note_ that these must be added __before__ binding the adapter to the `ViewGroup`. This is because the adapter treats headers and footers as different item types. Unfortunately, `ListView` and `RecyclerView` do not treat dynamic viewtypes too kindly. \n\n### ViewGroup adapter\n\nSometimes we want to simply add a homogenous set of data to a `LinearLayout` or parent `ViewGroup` and don't want to or can't use a `ListView`. Instead of having to create a `BaseAdapter`, write methods to bind the views to the `ViewGroup`, and handle changes to the adapter, we wrote `ViewGroupAdapter`.\n\nYou don't even need to worry about it because its the same interface for `ListView`, `RecyclerView`, and `ViewPager`.\n\n```javaadd\n\nLinearLayout layout = (LinearLayout) findViewById(R.id.my_list);\n\n// ties the adapter to this layout\n// any changes to the adapter will refresh the content on this layout\nUniversalConverterFactory.create(myListAdapter, layout);\n\n```\n\nThat's it!\n\n## Maintainers\n\n[Mervyn Anthony](https://github.com/Mervyn-Raizlabs)\n\n[Dylan R. James](https://github.com/dylanrjames)\n\n## Contributors\n\nTo become a contributor, please make pull requests against the `develop` branch and once code is merged, we'll add you!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frightpoint%2Funiversaladapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frightpoint%2Funiversaladapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frightpoint%2Funiversaladapter/lists"}