I have ListView which is customized to have a EditText box and a Button in it. The ListView displays text boxes as visible but the button as invisible. When the user clicks on an item in the ListView, the Button’s made visible. I have written the following code for the ListView:
public void onItemClick(AdapterView<?> list, View view, int position, long id) {
view.findViewById(R.id.button).setVisibility(View.VISIBLE);
}
The above code functions in the case when the first item’s Button and the second item’s Button are visible.
My problem:
When the next item in the ListView is clicked, the Button from the previous item should become invisible as the current item’s Button becomes visible. So how do I update the view of the previous item?
Store the previous row in a class variable:
Addition from comments
You’re right. The adapter’s view recycling is affecting the other rows so let’s extend whatever adapter you are using and override its
getView()method:And in your
onItemClick()method add a line like this: