【发布时间】:2016-03-15 03:08:26
【问题描述】:
在将此问题标记为重复之前,我知道很少有讨论这个特定主题的主题,但它们已经有几年历史了(2012-13 年),并且从那时起 Android API 已经发生了变化。此外,我已经尝试过这些解决方案,但要么它们不再起作用,要么因为我已将我的 ExpandableListView 与 ExpandableListAdapter 绑定(扩展 BaseExpandableListAdapter),所以这些解决方案不起作用。
这是我的问题:
我有一个ExpandableListView 在ExpandableListAdapter 扩展BaseExpandableListAdapter 的帮助下从静态文件中获取数据。
我在适配器中实现了getChildView() 和getGroupView() 方法来显示组项和子项。
我无法实现的是所选点击项目的平滑自动滚动到顶部。像这样:Auto scrolling in ExpandableListView
上述线程 (ListView.setSelection(position)) 中列出的解决方案不适用于我的情况。我试过了。类似的解决方案,如 (android:transcriptMode="disabled or smoothScroll or normal") 或 (ExpandableListView.smoothScrollToPositionFromTop(scrollTo, 0)) 并没有给出预期的结果。我不确定有什么问题。没有错误或警告或任何东西。
很少有线程说在适配器的onGroupExpand() 方法中调用您的ExpandableListView。首先,这种方法不再存在,但我想他们指的是现在的getChildView() 方法。但是这里的项目是从 View convertView 获取的,这是子项目的 XML 布局,我在这个布局中没有 ExpandableListView。我在我的MainActivity 中有它。
也许我对这个简单的问题感到困惑。有人可以指导我缺少什么以及如何达到预期的结果吗?
【问题讨论】:
-
您是否尝试过stackoverflow.com/questions/12762958/… 上的 onGroupExpanded 答案? onGroupExpanded 尚未被弃用 (developer.android.com/reference/android/widget/…)。
标签: android expandablelistview