[英]How to implement Click Listener in ExpandableListView
I have a custom adapter, which extends BaseExpandableListAdapter
. 我有一个自定义适配器,它扩展了BaseExpandableListAdapter
。
I want my ExpandableList
to expand and collapse when I'm clicking some TextView
. 当我单击某些TextView
时,我希望ExpandableList
展开和折叠。
How should I implement it? 我应该如何实施?
I suppose, i have to add OnClickListener
to methods getGroupView
and getChildView
. 我想,我必须将OnClickListener
添加到方法getGroupView
和getChildView
。 And I see, there is boolean flag isExpanded
. 而且我看到有一个布尔标志isExpanded
。
So it should look like this: 所以它应该看起来像这样:
@Override
public View getGroupView(int groupPosition, final boolean isExpanded,
View convertView, ViewGroup parent) {
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isExpanded){
//What should i write here?
}
}
});
return convertView;
}
But what should I write in OnClickListener
? 但是我应该在OnClickListener
中OnClickListener
? I cannot find any functions, which allow me to expand/collapse my listview. 我找不到任何可以扩展/折叠列表视图的函数。
Is there any function like listView.expandGroup(itemPosition);
是否有类似listView.expandGroup(itemPosition);
? ?
There actually is an ExpandableListView.expandGroup . 实际上有一个ExpandableListView.expandGroup 。 And it's reverse action collapseGroup . 这是相反的动作crashGroup 。
If the TextView
you are referring to is inside a listview item, then you are correct to the action inside an onClickListener
inside the adapter. 如果您要引用的TextView
在listview项内,那么您对适配器内onClickListener
内的操作是正确的。 This post talks about expanding an ExpandableListView
dynamically, I think you can just get the idea and reverse the action in order to do what you are aiming for. 这篇文章讨论了动态扩展ExpandableListView
,我认为您可以了解想法并反转操作以完成您的目标。
Hope this helps. 希望这可以帮助。 Cheers! 干杯! :D :D
The TextView you want to works as expand or collapse button for a group when you click on it must be a header of the ExpandableListViewAdapter. 要在其上单击时用作组的展开或折叠按钮的TextView必须是ExpandableListViewAdapter的标题。
Also you have setOnGroupExpandListener, and setOnGroupCollapseListener that triggers when a group is expanded or collapsed. 另外,您还有setOnGroupExpandListener和setOnGroupCollapseListener,它们在组展开或折叠时触发。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.