android可扩展列表视图从子onclick侦听器获取组的视图 [英] android expandable list view get view of group from child onclick listener
问题描述
我在我的应用程序中有一个可扩展的列表视图,每个组都有一个文本视图,说T具有动态值,每个组中都有一个单独的子级.我想引用已单击其子项的该组的T文本视图对象,以便我可以根据所单击的子项相应地更改T的值.
i have a expandable list view in my app, each group has a textview say T having dynamic value and each group has a single child within it. I want to refer to that T textview object of that Group whose child has been clicked on so that i can change the value of T accordingly as per the child item clicked.
在使用groupClickListener的情况下,我可以轻松获取TextView对象,但是在使用childClickListener的情况下,则无法获取...请在此处查看两者.
I can easily get the TextView Object in case of groupClickListener but iam not able to get in case of childClickListener... pls see both here.
mExpandableListView.setOnGroupClickListener(new OnGroupClickListener(){
mExpandableListView.setOnGroupClickListener(new OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
// TODO Auto-generated method stub
TextView moreTextView = (TextView)v.findViewById(R.id.group_more); // this works fine
}
return false;
}
});
mExpandableListView.setOnChildClickListener(new OnChildClickListener(){
mExpandableListView.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
// TODO Auto-generated method stub
boolean isExpanded=false;
if(groupStatus[groupPosition]==1)
{
isExpanded=true;
}
View v1 = parent.getExpandableListAdapter().getGroupView(groupPosition, isExpanded, v, parent);
TextView moreTextView = (TextView)v1.findViewById(R.id.group_more); // doesn,t work as v1 is null all the times
return false;
}
});
推荐答案
// Listview on child click listener
expListView.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
// TODO Auto-generated method stub
Toast.makeText(
getApplicationContext(),
listDataHeader.get(groupPosition)
+ " : "
+ listDataChild.get(
listDataHeader.get(groupPosition)).get(
childPosition), Toast.LENGTH_SHORT)
.show();
return false;
}
});
我希望它对您有用.
这篇关于android可扩展列表视图从子onclick侦听器获取组的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!