我正在使用带有扩展 BaseExpandableListAdapter 的自定义适配器的 ExpandableListView。 现在我想在那个可扩展列表中添加一个标题,所以我不需要使用我的 apapter 来获取元素的 View ,而是使用标题“自动”创建的元素,这样我就不会得到 IndexOutOfBoundsExceptions 因为现在标题是0位置的元素。
在我的适配器不可扩展的其他情况下,我只需要调用 myList.getAdapter() 并且一切正常,但现在我需要获取扩展 BaseExpandableListAdapter 的适配器,但我找不到实现它的方法。
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 );
有时,我需要为 myAdapter(扩展 BaseExpandableListAdapter)调用 getChildView 方法,但我不能直接使用 myAdapter,因为它没有 header 。我需要通过列表来完成。我正在尝试通过 getWrappedAdapter 来完成
HeaderViewListAdapter headerAdapter = ((HeaderViewListAdapter) myList .getAdapter());
((MyAdapter ) headerAdapter.getWrappedAdapter()).getChildView(0, i - 1, false, view, myList );
但它给了我一个 ClassCastException,android.widget.ExpandableListConnector 无法转换为 MyAdapter
有谁知道通过列表方法获取原始适配器的方法吗?
谢谢
最佳答案
来自docs ,
public ListAdapter getAdapter ()
Added in API level 1
This method should not be used, use getExpandableListAdapter().
所以使用,getExpandableListAdapter()
然后getChildView
关于android - 使用 header 从可扩展 ListView 中检索原始适配器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16988979/