Reputation: 228
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.
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() {
@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() {
@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;
}
});
Upvotes: 2
Views: 9416
Reputation: 384
Use the getExpandableListAdapter()
on the "parent" and define your custom classes accordingly.
Then modify the values within the custom objects - the ExpandableListView will update automatically.
E.g.:
@Override
public boolean onChildClick(ExpandableListView _parent, View _v,
int _groupPosition, int _childPosition, long _id
) {
// do required casts for your custom objects for groups and childs.
// In my case, I'm using class "Group"
Group group=(Group)parent.getExpandableListAdapter().getGroup(_groupPosition);
// In my case, I'm using class "Child"
Child item=(Child)optionsList.getExpandableListAdapter().getChild(_groupPosition, _childPosition);
// In my custom Group class, I've defined a field that populates a different
// TextView within the Group layout - so, getter/setter method for "selection" were defined.
// The ExpandableListView will be updated automatically based on the adapter updates.
group.setSelection(item.getName());
return true;
}
Not exactly sure why this happens - it seems like the ExpandableAdapter is tracking changes to the model itself... I don't have time to check the details on this.. but it works.
Upvotes: 1
Reputation: 11188
// 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;
}
});
I hope its useful for you.
Upvotes: 4