【问题标题】:Auto Scrolling Clicked Group of ExpandableListView (binding with BaseExpandableListAdapter)ExpandableListView 的自动滚动点击组(与 BaseExpandableListAdapter 绑定)
【发布时间】:2016-03-15 03:08:26
【问题描述】:

在将此问题标记为重复之前,我知道很少有讨论这个特定主题的主题,但它们已经有几年历史了(2012-13 年),并且从那时起 Android API 已经发生了变化。此外,我已经尝试过这些解决方案,但要么它们不再起作用,要么因为我已将我的 ExpandableListViewExpandableListAdapter 绑定(扩展 BaseExpandableListAdapter),所以这些解决方案不起作用。

这是我的问题: 我有一个ExpandableListViewExpandableListAdapter 扩展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 中有它。

也许我对这个简单的问题感到困惑。有人可以指导我缺少什么以及如何达到预期的结果吗?

【问题讨论】:

标签: android expandablelistview


【解决方案1】:

我遇到了同样的问题。在孩子我只有一个 TextView,它是绑定的。最重要的是,在滚动到“扩展组”的那一刻,由于绑定,这个 TextView 的高度未知。文字是后来设置的。所以,我在我的适配器中手动设置:

@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
    InfoModelView info = (InfoModelView) getChild(groupPosition,childPosition);

    SubitemBinding binding = DataBindingUtil.inflate(LayoutInflater.from(this.context),R.layout.elv_child, parent, false);

    if (info != null){
        binding.setInfo(info);
        binding.lblListItem.setText(info.getDescription());
    }

    return binding.getRoot();
}

我觉得,现在我不再需要那些围绕绑定的工作人员了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-10
    • 2017-01-30
    • 2011-08-19
    • 1970-01-01
    • 1970-01-01
    • 2015-11-18
    相关资源
    最近更新 更多