android - 使用 header 从可扩展 ListView 中检索原始适配器

标签 android expandablelistview

我正在使用带有扩展 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/

相关文章:

java - Android Java MVC结构

android - SpannableString 在横向模式下显示不正确

android - 错误文件不是 SQLite 3 数据库

android - FileObserver 不工作 android 4.4.3

android - Android RatingBar 对某些设备有 "bad"阈值,修复了吗?

Android:父组中带有按钮的可扩展列表

android - 当组扩展时,自动滚动到最后一个子项

android - Expandablelistview 展开时背景变黑

android - 如何在抽屉导航内集成可扩展 ListView ?

android - 在为 N 级或多级可扩展 ListView 维护折叠/展开状态后,某些子组未显示