{"id":13848951,"url":"https://github.com/commonsguy/cwac-merge","last_synced_at":"2025-05-04T21:09:01.861Z","repository":{"id":618733,"uuid":"257772","full_name":"commonsguy/cwac-merge","owner":"commonsguy","description":"CommonsWare Android Components: MergeAdapter","archived":false,"fork":false,"pushed_at":"2019-05-17T12:35:15.000Z","size":96,"stargazers_count":592,"open_issues_count":2,"forks_count":120,"subscribers_count":41,"default_branch":"master","last_synced_at":"2025-05-04T21:08:57.257Z","etag":null,"topics":["android","android-library","android-listview"],"latest_commit_sha":null,"homepage":"http://commonsware.com/cwac","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/commonsguy.png","metadata":{"files":{"readme":"README.markdown","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2009-07-22T16:31:51.000Z","updated_at":"2025-04-20T09:26:06.000Z","dependencies_parsed_at":"2022-07-05T04:00:24.369Z","dependency_job_id":null,"html_url":"https://github.com/commonsguy/cwac-merge","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commonsguy%2Fcwac-merge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commonsguy%2Fcwac-merge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commonsguy%2Fcwac-merge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/commonsguy%2Fcwac-merge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/commonsguy","download_url":"https://codeload.github.com/commonsguy/cwac-merge/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252399517,"owners_count":21741672,"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":["android","android-library","android-listview"],"created_at":"2024-08-04T19:01:02.777Z","updated_at":"2025-05-04T21:09:01.842Z","avatar_url":"https://github.com/commonsguy.png","language":"Java","funding_links":[],"categories":["Java"],"sub_categories":[],"readme":"CWAC MergeAdapter: Stitching Together Rows\n==========================================\n\n**NOTE**: This project has been discontinued. This repository will be made private on 1 June 2020.\n\n`MergeAdapter` accepts a mix of `Adapter`s and `View`s and\npresents them as one contiguous whole to whatever `ListView`\nit is poured into. This is good for cases where you have\nmultiple data sources, or if you have a handful of ordinary\n`View`s to mix in with lists of data, or the like.\n\nSimply create a `MergeAdapter` and call `addAdapter()`,\n`addView()`, or `addViews()` (latter accepting a `List\u003cView\u003e`),\nthen attach your adapter to the `ListView`. \n\nThere is also `MergeSpinnerAdapter` for use with `Spinner`\nwidgets.\n\nInstallation\n------------\nThis Android library project is \n[available as a JAR](https://github.com/commonsguy/cwac-merge/releases).\nIf you wish to use the JAR, you will need to also add the JAR from\n[the CWAC-Sacklist project](http://github.com/commonsguy/cwac-sacklist) to your\nproject.\n\nNOTE: The JAR name, as of v1.0.4, has a `cwac-` prefix, to help distinguish it from other JARs.\n\nAlso note that if you plan to use this as an Android library project\nin source form, you\nwill also need to download [the CWAC-Sacklist project](http://github.com/commonsguy/cwac-sacklist)\n(and, if needed, modify this project's configuration to point to your copy of\nCWAC-Sacklist library project). Alternatively, download the CWAC-Sacklist JAR into\nthe `libs/` directory of your clone of this project and remove the dependency on\nthe CWAC-Sacklist library project.\n\nThis project is also available as\nan artifact for use with Gradle. To use that, add the following\nblocks to your `build.gradle` file:\n\n```groovy\nrepositories {\n    maven {\n        url \"https://s3.amazonaws.com/repo.commonsware.com\"\n    }\n}\n\ndependencies {\n    compile 'com.commonsware.cwac:merge:1.1.2'\n}\n```\n\nOr, if you cannot use SSL, use `http://repo.commonsware.com` for the repository\nURL. This should automatically pull down the CWAC-Sacklist dependency.\n\nUsage\n-----\nYou can use `MergeAdapter` directly or subclass it. The\nlatter is needed to support controlling which rows are/are\nnot enabled.\n\n### Constructors\n\nThere is only one, no-argument constructor at this time. Just\ncall `new MergeAdapter()` or `new MergeSpinnerAdapter()` and\nyou are on your way!\n\n### Adding Content\n\nYou have three methods for defining what goes into the\n`MergeAdapter`. You can call `addAdapter()` to have all of that\nadapter's rows appear in the combined roster. You can call\n`addView()` to add a single `View` as a row. You can also call\n`addViews()` to add a `List` of `View` objects to use as rows.\n\n**NOTE**: `MergeSpinnerAdapter` only supports `addAdapter()`.\n\nEach of these will appear in combined roster in the order\nthey were added.\n\nThe `addView()` and `addViews()` methods have a variant that\naccepts a boolean 2nd parameter. Set this boolean to true if you\nwant the rows represented by these views to be enabled (i.e.,\nselectable). The default is that they are disabled, for use\nas if they were header rows. For adapters added via `addAdapter()`,\nthe determination of whether or not rows are enabled is determined\nby the underlying adapter.\n\n### Other Methods to Override\n\nYou are welcome to override other methods as well, since this\nis just an `Adapter`.\n\n### Supporting isEnabled()\n\nIf you wish, your adapters wrapped by `MergeAdapter` can override `isEnabled()`,\nand `MergeAdapter` should enable and disable the rows as directed.\n\n### Timing\n\nYou must pour the contents into the `MergeAdapter` *before*\ncalling `setListAdapter()` to associate the `MergeAdapter`\nwith a `ListView`. This limitation is required because Android\nonly calls getViewTypeCount() once, and adding more views or\nadapters adds more view types.\n\nNote, though, that you can modify the underlying adapters. So,\nfor example, if you add a `CursorAdapter` to the `MergeAdapter`,\nand you `requery()` the `Cursor`, the changes should be reflected\nvia the `MergeAdapter` to whatever `AdapterView` the `MergeAdapter`\nis connected to.\n\n### Supporting `android:id/empty`\n\nA `ListActivity` supports a widget in its layout, with an `android:id`\nof `@android:id/empty`, which will be displayed if the list is\nempty. More specifically, it will be displayed if the `MergeAdapter`\nreturns `true` for `isEmpty()`. The default implementation of\n`isEmpty()` in `BaseAdapter` checks `getCount()` and compares it to `0`.\n\nIn many cases, this default will be fine. However, if you are\nadding regular `View`s to the adapter (e.g., section headings),\nthen `getCount()` will include these additional rows, and so `isEmpty()`\nwill never return `true`. In this case, you may need to override\n`isEmpty()` to implement your own business logic to determine\nwhen the list is, indeed, \"empty\".\n\n### Contents of `MergeSpinnerAdapter`\n\nYou should add properly-configured `SpinnerAdapter` implementations\n(e.g., `ArrayAdapter`, `CursorAdapter`) to a `MergeSpinnerAdapter`\nto have it work properly.\n\n### Active/Inactive Contents\n\nBy default, everything that you add to the `MergeAdapter` is \"active\" and\ncontributes to the resulting compound contents. However, you can call\n`setActive()` to toggle whether some piece is active or inactive. Inactive\npieces do not contribute to the contents, removing them entirely from the\n`ListView` (or wherever you are using this).\n\nThere are two flavors of `setActive()`. Both take a `boolean` second parameter,\nwith `true` meaning the piece is active and `false` for inactive. The first\nparameter is either a `ListAdapter` that you added already or a `View` that\nyou added already (individually or as part of a `List`).\n\n### IGNORE_ITEM_VIEW_TYPE and ITEM_VIEW_TYPE_IGNORE\n\nNeither `IGNORE_ITEM_VIEW_TYPE` from `Adapter` nor `ITEM_VIEW_TYPE_IGNORE` from\n`AdapterView` are honored by `MergeAdapter`. That's mostly because there is no\nevidence that either constant is used inside of Android, and the documentation\nfor each is shaky at best. If you find a use case for either of these values,\nplease post an [issue](https://github.com/commonsguy/cwac-merge/issues),\nwith enough information to reproduce the use case and therefore confirm that\na modified `MergeAdapter` does what it is supposed to.\n\n### JavaDocs\n\n[JavaDocs are available](http://javadocs.commonsware.com/cwac/merge/index.html)\nfor your JavaDocing pleasure.\n\nDependencies\n------------\nThis project requires the [CWAC SackOfViewsAdapter][sacklist].\nA copy of a compatible JAR can be found in the `libs/` directory of\nthe project, though you are welcome to try newer ones, or\nones that you have patched yourself. Users of the AAR artifact will automatically\ndownload this dependency.\n\nThis project should work on API Level 4 and higher, except for any portions that\nmay be noted otherwise in this document. Please report bugs if you find features\nthat do not work on API Level 4 and are not noted as requiring a higher version.\n\nVersion\n-------\nThis is version v1.1.2 of this module.\n\nFor those of you updating from a previous version, please note that you need\na new edition of the `SackOfViewsAdapter` JAR as well.\n\nDemo\n----\nIn the `demo/` sub-project you will find\na sample activity that demonstrates the use of `MergeAdapter`.\n\nNote that when you build the JAR via `ant jar`, the sample\nactivity is not included, nor any resources -- only the\ncompiled classes for the actual library are put into the JAR.\n\nLicense\n-------\nThe code in this project is licensed under the Apache\nSoftware License 2.0, per the terms of the included LICENSE\nfile.\n\nQuestions\n---------\nIf you have questions regarding the use of this code, please post a question\non [Stack Overflow](http://stackoverflow.com/questions/ask) tagged with\n`commonsware-cwac` and `android` after [searching to see if there already is an answer](https://stackoverflow.com/search?q=[android]+mergeadapter). Be sure to indicate\nwhat CWAC module you are having issues with, and be sure to include source code \nand stack traces if you are encountering crashes.\n\nIf you have encountered what is clearly a bug, please post an [issue](https://github.com/commonsguy/cwac-merge/issues). Be certain to include complete steps\nfor reproducing the issue.\nThe [contribution guidelines](CONTRIBUTING.md)\nprovide some suggestions for how to create a bug report that will get\nthe problem fixed the fastest.\n\nYou are also welcome to join\n[the CommonsWare Community](https://community.commonsware.com/)\nand post questions\nand ideas to [the CWAC category](https://community.commonsware.com/c/cwac).\n\nDo not ask for help via social media.\n\nRelease Notes\n-------------\n- v1.1.2: reorganized project into Android Studio-standard structure\n- v1.1.1: updated for Android Studio 1.0 and new AAR publishing system\n- v1.1.0: added `android:minSdkVersion` to library manifest\n- v1.0.4: added `cwac-` prefix to JAR\n- v1.0.3: re-fixed manifest to better handle manifest merging per issue #14\n- v1.0.2: fixed manifest to better handle manifest merging\n- v1.0.1: added Gradle files and published AAR\n- v1.0.0: milestone considered reached\n- v0.4.0: added `setActive()`\n- v0.3.1: added workaround for http://code.google.com/p/android/issues/detail?id=16155\n- v0.3.0: added `MergeSpinnerAdapter` support\n- v0.2.1: added `getAdapter()` method to return the `ListAdapter` associated with a given position\n- v0.2.0: converted to Android library project, added enabled versions of `addView()` and `addViews()`, correctly cascades data set changes from underlying adapters\n\nWho Made This?\n--------------\n\u003ca href=\"http://commonsware.com\"\u003e![CommonsWare](http://commonsware.com/images/logo.png)\u003c/a\u003e\n\n[sacklist]: http://github.com/commonsguy/cwac-sacklist/tree/master\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcommonsguy%2Fcwac-merge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcommonsguy%2Fcwac-merge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcommonsguy%2Fcwac-merge/lists"}