I have 2 buttons
in my expandablelistiview
child, first button View.VISIBLE
, and another one View.GONE
. I tried to make the first button change the second button visibility become visible, but it's not working.
My getchildview method:
@Override
public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView,
ViewGroup parent) {
final String childText = (String) getChild(groupPosition, childPosition);
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) this.mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_item, null);
}
buttonOff = (Button) convertView.findViewById(R.id.button_off);
buttonOff.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
buttonOff.setVisibility(View.GONE);
buttonTest.setVisibility(View.VISIBLE);
}
});
buttonTest = (Button) convertView.findViewById(R.id.button_test);
buttonTest.setVisibility(View.GONE);
buttonTest.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
buttonTest.setVisibility(View.GONE);
buttonOff.setVisibility(View.VISIBLE);
}
});
TextView listChildText = (TextView) convertView.findViewById(R.id.list_item);
listChildText.setText(childText);
return convertView;
}
Your code is not working because you are not maintaining the state of the buttons. Initialize button state for all of your rows. Then every time your getView() method is called, first check the state and depending on that you can set which button to make visible. When a button is clicked you need to update the status of that row. Below code can guide you in that direction: