{"id":18810005,"url":"https://github.com/aryaxt/abstractgroupedadapter","last_synced_at":"2025-07-26T23:37:11.351Z","repository":{"id":11023656,"uuid":"13353749","full_name":"aryaxt/AbstractGroupedAdapter","owner":"aryaxt","description":"A simple way to implement grouped ListView on Android","archived":false,"fork":false,"pushed_at":"2013-10-05T23:13:42.000Z","size":532,"stargazers_count":1,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-20T08:06:46.723Z","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":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aryaxt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"License.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-10-05T22:39:04.000Z","updated_at":"2018-01-03T10:02:13.000Z","dependencies_parsed_at":"2022-08-20T12:31:01.566Z","dependency_job_id":null,"html_url":"https://github.com/aryaxt/AbstractGroupedAdapter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/aryaxt/AbstractGroupedAdapter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aryaxt%2FAbstractGroupedAdapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aryaxt%2FAbstractGroupedAdapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aryaxt%2FAbstractGroupedAdapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aryaxt%2FAbstractGroupedAdapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aryaxt","download_url":"https://codeload.github.com/aryaxt/AbstractGroupedAdapter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aryaxt%2FAbstractGroupedAdapter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260907157,"owners_count":23080612,"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-07T23:18:29.738Z","updated_at":"2025-06-20T08:07:00.632Z","avatar_url":"https://github.com/aryaxt.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"AbstractGroupedAdapter\n======================\n\nA simple way to implement grouped ListView on Android\n\nStep 1\n------------------\nCreate 2 xml files 1 representing the header, and another representing the row\n\nHeader\n\n```xml\n\u003cRelativeLayout 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:minHeight=\"45dp\"\n    android:background=\"#FFFFCC\" \u003e\n\n    \u003cTextView\n        android:id=\"@+id/txtHeaderTitle\"\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\" /\u003e\n\n\u003c/RelativeLayout\u003e\n```\n\nRow\n\n```xml\n\u003cRelativeLayout 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:minHeight=\"35dp\" \u003e\n\n    \u003cTextView\n        android:id=\"@+id/txtPersonName\"\n        android:layout_width=\"wrap_content\"\n        android:layout_height=\"wrap_content\"  /\u003e\n\n\u003c/RelativeLayout\u003e\n```\nStep 2\n------------------\nCreate a new Adapter inheriting from AbstractGroupedAdapter.\n\nAbstractGroupedAdapter takes 2 generic types, the first one represents the object used to populate the header, the second one represents the object that is used to populate each row.\n```java\npublic class MyAdapter extends AbstractGroupedAdapter\u003cString, Person\u003e {\n\n\tpublic MyAdapter(Context context) {\n\t\tsuper(context);\n\t}\n\t\n\t@Override\n\tpublic View getView(int position, View view, ViewGroup parent) {\n\t\n\t\tif (this.isItemHeader(position)) {\n\t\t\tString header = this.getHeader(position);\n\t\t\t\n\t\t\tview = getReusableView(view, R.layout.header);\n\t\t\tTextView textView = (TextView) view.findViewById(R.id.txtHeaderTitle);\n\t\t\ttextView.setText(header);\n\t\t}\n\t\telse {\n\t\t\tPerson person = this.getItem(position);\n\t\t\t\n\t\t\tview = getReusableView(view, R.layout.row);\n\t\t\tTextView textView = (TextView) view.findViewById(R.id.txtPersonName);\n\t\t\ttextView.setText(person.getName());\n\t\t}\n\n\t\treturn view;\n\t}\n}\n```\n\nStep 3\n------------------\nCreate a Map with your data and pass it to the adapter\n\n```java\nMap\u003cString, List\u003cPerson\u003e\u003e data = new HashMap\u003cString, List\u003cPerson\u003e\u003e();\n\t\t\nList\u003cPerson\u003e aPersons = new ArrayList\u003cPerson\u003e();\naPersons.add(new Person(\"Aryan\"));\naPersons.add(new Person(\"Alex\"));\naPersons.add(new Person(\"Andrew\"));\ndata.put(\"A\", aPersons);\n\t\t\nList\u003cPerson\u003e bPersons = new ArrayList\u003cPerson\u003e();\nbPersons.add(new Person(\"Bob\"));\nbPersons.add(new Person(\"Bastard\"));\nbPersons.add(new Person(\"Banana\"));\nbPersons.add(new Person(\"Brandon\"));\ndata.put(\"B\", bPersons);\n\nMyAdapter adapter = new MyAdapter(this);\nadapter.setData(data);\nlistView.setAdapter(adapter);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faryaxt%2Fabstractgroupedadapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faryaxt%2Fabstractgroupedadapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faryaxt%2Fabstractgroupedadapter/lists"}