I have ExpandableListView, under that there a is group which contains multiple Button Views as Child View. Below is the code for Button Views inside getChildView(),

Button button[] = new Button[cost.size()];

                button[childPosition] = new Button(context);
                button[childPosition].setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
                button[childPosition].setText(cost.get(childPosition));
                linearLayout.addView(cost[childPosition]);
                linearLayout.setGravity(Gravity.CENTER_HORIZONTAL);

What I need to achieve is,

Consider there is 4 buttons. Now I tapped 2nd button. So background color of 2nd button will change to different color and button which has highlighted already also need to change back to the previous color.

My problem is,

When I try to use for loop to achieve that logic, got null object reference for other buttons except the button which I pressed.

Thanks in Advance.

0

There are 0 best solutions below