答案 0 :(得分:0)
使用ExpandableListView.OnGroupClickListener。
实现侦听器并单击它时调用的方法是:
public preloadImages(imgUrls: string[]) {
console.log(this.cachedResources); //Everything is fine here
return Observable.from(imgUrls).concatMap(url=> Observable.of(this.getImage(url));
}
如果您想要更精细的控制,还可以实现听众ExpandableListView.OnGroupCollapseListener和ExpandableListView.OnGroupExpandListener。
要实现它,声明一个实现OnGroupClickListener的对象,或者创建一个匿名类:
void onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
// int position and other parameters give you everything you need to know about the click
}
然后,从你的Fragment视图中获取你的ExpandableListView(你可能会这样做,我只是在这里猜测,如果不是那样的话):
ExpandableListView.OnGroupClickListener mListener =
new ExpandableListView.OnGroupClickListener({
public void onGroupClick(ExpandableListView parent, View v, int groupPosition, long id){
//handle whatever you want to do on the click in this method
}
});
最后,将侦听器添加到ExpandableListView:
ExpandableListView listView =
(ExpandableListView) this.getView()
.findViewById(R.id.whatever_you_set_your_expandablelistview_id_to);
你的听众" onGroupClick"每当点击一个组时都会被调用。请注意,您可能只能为每个ExpandableListView添加一个侦听器。 Also, be careful of Context leaks when using anonymous classes for listeners on views!