Is it possible to remove view or adapter from MergeAdapter
somehow? I'd try to extend it and remove the view from pieces
but it's private
. Or maybe there's an alternative solution to show/hide view in this adapter? I tried to set its layout_height
to zero and visibility to View.GONE
, but it still shows the empty list item. Thanks in advance.

- 986,068
- 189
- 2,389
- 2,491

- 9,208
- 4
- 44
- 51
4 Answers
To remove a view or an adapter from MergeAdapter
use the following methods:
setActive()
on your mergeAdapter Instance.
For Example :
To remove a Textview
(mytextView) from a MergeAdapter
(merAdapter) use:
merAdapter.setActive(mytextViiew,false);
And to enable it again(to make it visible) use:
merAdapter.setActive(mytextViiew,true);
Refer the MergeAdapter
documentation for details:

- 8,233
- 3
- 36
- 60

- 408
- 3
- 14
Is it possible to remove view or adapter from MergeAdapter somehow?
Not presently, sorry. It shouldn't be too hard to add (remove it from the collection and call notifyDataSetChanged()
to update the AdapterView
) if you wanted to take a shot at it. Contributions are welcome! :-)

- 986,068
- 189
- 2,389
- 2,491
your MergeAdapter should be having method called getCount()
.. if i have understood you right, returning zero from there may solve your problem..

- 13,398
- 4
- 44
- 60
-
Hi ntc, I assume that returning zero in `getCount()` will hide all views, but I need to hide specific one. For example, I added 2 views, 2 adapters, then again 2 views, and now I wanna remove/hide the 2-nd view. – ernazm Aug 04 '11 at 10:09
-
well then on getView() method you will get the position of the view requested.. at required position you can set its Visibility as gone.. if you can post bit of your code probably we will be more clear about your purpose,.. – ngesh Aug 04 '11 at 10:14
-
Though setting Visibility of the view onside the `getView()` doesn't hide the list item, I'll try to don't attach the view overriding this method, so thanks for the tip. – ernazm Aug 04 '11 at 10:25
-
Ended up with returning the new view with `ListView.LayoutParams` with `width` 0 in `getView()`. I'll accept your answer if the `MergeAdapter`'s author won't reply. Thanks again. – ernazm Aug 04 '11 at 10:48
Expanding on Mark Murphy's answer, I think this is as simple as adding this method to MergeAdapter:
public void removeAdapter(ListAdapter la) {
pieces.remove(la);
}
remove()
takes an object and will do all of the necessary testing & removal for you, if that object is contained in the pieces list. You could make this return a bool or something for your own purposes, but I had no such need.
Then just call something like:
int view_to_remove = *AN_INT*
adapter.removeAdapter(listAdapter.getAdapter(view_to_remove));
adapter.notifyDataSetChanged();

- 1,920
- 1
- 18
- 20
-
If I remember it right, `pieces` has private access in MergeAdapter, so I'd need to modify its sources. I'm not so familiar with GitHub and contributions there so I ended up with some workaround. But thanks for the suggestion. – ernazm Nov 02 '11 at 21:46