Android onClickListener strange behavior
i'm trying to set a child click listener on my ExpandedListView, and i'm getting some strange results:
theList.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View view, int groupPosition, int childPosition, long id) {
Log.i(LOG_TAG, "clicked");
ExpandableListAdapter adapter = parent.getExpandableListAdapter();
View v = (View)adapter.getChild(groupPosition, childPosition);
Toast toast = Toast.makeText(getApplicationContext(),
"item: " + new Integer(groupPosition).toString() + ":" + new Integer(childPosition).toString(),
Toast.LENGTH_SHORT);
toast.show();
if (!((CheckedTextView)view.findViewById(R.id.check)).isChecked()){
((CheckedTextView)view.findViewById(R.id.check)).setChecked(true);
} else {
((CheckedTextView)view.findViewById(R.id.check)).setChecked(false);
}
return true;
}
});
it sort of works. when i check one of the items, howev开发者_StackOverflow中文版er, another, additional item will also be selected, seemingly at random. am i not doin this correctly?
Solved the issue myself. i ended up extending the adapter class and overriding getChildView and getGroupView and added a list of booleans to the adapter to keep up with the checkmarks. probably not the most sophisticated solution, but works perfectly.
精彩评论