You can do this by making some changes to your custom adapter getGroupView and adding two more methods to the custom adapter , which will be called depending on the kind of clicked. Here I am posting a sample code:
public void OnIndicatorClick(boolean isExpanded, int position){
}
public void OnTextClick(){
}
@Override
public View getGroupView(final int groupPosition, final boolean isExpanded,
View convertView, ViewGroup parent) {
String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_group, null);
}
TextView lblListHeader = (TextView) convertView
.findViewById(R.id.lblListHeader);
lblListHeader.setText(headerTitle);
lblListHeader.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(_context, "text Clicked", Toast.LENGTH_LONG).show();
}
});
ImageView indicator = (ImageView) convertView.findViewById(R.id.imageview_list_group_indicator);
indicator.setSelected(isExpanded);
indicator.setTag(groupPosition);
indicator.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int position = (Integer)v.getTag();
Toast.makeText(_context, "Indicator Clicked", Toast.LENGTH_LONG).show();
OnIndicatorClick(isExpanded,position);
}
});
return convertView;
}
And now from Activity you can call the Custom Adapter , as shown below, which will override the two methods that we added to the Custom Adapter
ExpandableListAdapter listAdapter = new ExpandableListAdapter(MainActivity.this,
listDataHeader, childDataList){
@Override
public void OnIndicatorClick(boolean isExpanded, int position) {
if(isExpanded){
expandableListView.collapseGroup(position);
}else{
expandableListView.expandGroup(position);
}
}
@Override
public void OnTextClick() {
}
};
expandableListView.setAdapter(listAdapter);
source
share