I have an expandableList Adapter working pretty well, but something in baffling me. On each child lists I have 2 buttons and a textview. I would like to make it some that when I click one button (+) that the textview number goes up and when I click the other button (-) that the textview number goes down.
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 infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.list_item, null);
}
final TextView txtListChild = (TextView) convertView
.findViewById(R.id.lblListItem);
Button btnMinus = (Button) convertView
.findViewById(R.id.btnMinus);
btnMinus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LinearLayout ll = (LinearLayout) v.getParent();
TextView tv1 = (TextView) ll.getChildAt(1);
String Count = tv1.getText().toString();
int num = Integer.parseInt(Count);
num = num - 1;
tv1.setText(Integer.toString(num));
}
So the above code works as I would expect it, the button is clicked the textview goes down by one and we all is good.
But here is where I am getting confused. If I open another part of the list and look at another list of children one of the TextViews in that list has also changed! So in short clicking a button in one child is not only affecting the text view right next to it, but is also affecting a text view in a completely different header.