Android 来自 Google 的 ExpandableListView 示例

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3483690/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 10:25:01  来源:igfitidea点击:

ExpandableListView sample from Google

androidexpandablelistview

提问by Waza_Be

I just tried the current Google sample for ExpandableListiew:

我刚刚尝试了当前的 Google 示例ExpandableListiew

This sample seem very simple and easy to use, but what I would like to do is to say that one of the category has no child. I removed all the children but the problem is that the arrow still appears on this current line.

这个示例看起来非常简单易用,但我想做的是说其中一个类别没有子项。我删除了所有孩子,但问题是箭头仍然出现在当前行上。

For instance, imagine that I remove all "Cat Names", the arrow is still there and when I click on it, the arrow just change. How to remove this arrow and launch an activity instead?

例如,假设我删除了所有"Cat Names",箭头仍然存在,当我点击它时,箭头就会改变。如何删除此箭头并改为启动活动?

回答by FearlessHyena

If you're talking about the arrow that is used to collapse/expand the list then you can remove it by using setGroupIndicator()

如果您正在谈论用于折叠/展开列表的箭头,那么您可以使用 setGroupIndicator() 将其删除

in the activity you can call

在您可以调用的活动中

getExpandableListView().setGroupIndicator(null);

that will remove the arrow permanently though. If you want to only hide it if the list is empty you can do it through xml attributes like this

不过,这将永久删除箭头。如果你只想隐藏它,如果列表是空的,你可以通过像XML属性做

To launch an activity when the list is expanded/collapsed you can override onGroupExpanded (or collapsed) in your ListAdapter implementation and used that to fire up your activity

要在列表展开/折叠时启动活动,您可以在 ListAdapter 实现中覆盖 onGroupExpanded(或折叠)并使用它来启动您的活动

回答by Mohamed A.Karim

In general, if you want a specific area of your activity to be refreshed when you come back from another activity; you got to write in the onResume() method.

一般来说,如果您希望在您从另一个活动回来时刷新您活动的特定区域;你必须写在 onResume() 方法中。

Steps: 1 – In the Activity you want it to be refreshed, override the onResume() method:

步骤: 1 – 在您希望刷新的 Activity 中,覆盖 onResume() 方法:

@Override
protected void onResume() {
    super.onResume();
    // TODO: PUT YOUR REFRESH CODE IN HERE
}

2- You will need to refresh your Expandable Adapter.

2- 您需要刷新可扩展适配器。

I suggest you take the same code you used to instantiate your expandable list and put it again, like follows:

我建议您使用用于实例化可扩展列表的相同代码并再次放置,如下所示:

SimpleExpandableListAdapter expandableListAdapter =
    new SimpleExpandableListAdapter(
        this,
        YourPrentsList, // List of your parent 
        R.layout.parents_layout,    // Layout for the Parents
        new String[] { "groupKey" },    // Key in the Group Data maps to display
        new int[] { 1 },        
        childrenList,   // List of the children
        R.layout.childs_layout, // Layout of the children
        new String[] { "keys"}, 
        new int[] { 1}  
    );
setListAdapter( expandableListAdapter );

I hope this solves your concern... Thanks,

我希望这能解决您的疑虑...谢谢,

Mohamed.

穆罕默德。