I'm using a ExpandableListView with a custom adapter that extends BaseExpandableListAdapter. Now I want to add a header to that expandable list, so instead of using my apapter to get the view of the elements I need to use the one "automatically" created with the header so I don't get a IndexOutOfBoundsExceptions because now the header is a element at 0 position.
In other ocassions where my adapter was not expandable I just need to call myList.getAdapter() and everything was ok but now I need to get the adapter that extends BaseExpandableListAdapter and I can't find the way to do it.
myList = (ExpandableListView)findViewById(R.id.my_list);
myList .setGroupIndicator(null);
myList .setOnGroupClickListener(this);
myList .setOnChildClickListener(this);
//add a header
View addSummaryLayout = View.inflate(this, R.layout.add_summary, null);
groupedMultimediaListView.addHeaderView(addSummaryLayout);
myAdapter = new MyAdapter (this, uploadingMedias);
myList .setAdapter(myAdapter );
At some time, I need to call the getChildView method for myAdapter (extends BaseExpandableListAdapter) but I can't use directly myAdapter because that one doesn't have the header. I need to do it through the list. I'm trying to do it through the getWrappedAdapter
HeaderViewListAdapter headerAdapter = ((HeaderViewListAdapter) myList .getAdapter());
((MyAdapter ) headerAdapter.getWrappedAdapter()).getChildView(0, i - 1, false, view, myList );
but it's giving me a ClassCastException, android.widget.ExpandableListConnector cannot be cast to MyAdapter
Does anyone know a way to get the original adapter through the list methods?
Thank you
An adapter links an Android ExpandableListView with the underlying data. The implementation of this interface will provide access to the data of the children (categorized by groups), and also instantiate Views for children and groups.
Here, we will make a custom ExpandablelistView where a user can add data in the menu and can even add a new category. For adding new category, we will use a dropdown Spinner and a search button will be used to add products in that category.
This ArrayAdapter is filled with items as defined in Strings.xml as string-array. After filling Spinner, we are adding products one by one in Expandable list view through addProduct (). In the addProduct (), we are first checking if product is already present. If it's not, then it is added to the corresponding category.
The implementation of this interface will provide the data for the children and also initiate the views for the children and groups. For customization of List we need to implement ExpandableListAdapter in our custom Adapter.
From the docs,
public ListAdapter getAdapter ()
Added in API level 1
This method should not be used, use getExpandableListAdapter().
so use, getExpandableListAdapter()
and then getChildView
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With