In ListView, when an item exits the screen, ListView destroys the item for efficiency, and when scrolling back to that item, it recreates it by calling the adapter's getView () method, so you need to save an array that has a logical value for the button status, which by default will be appear as visible, and in getView () you just place the check, getting the logical status value from the logical array, if true, then the element will be visible, otherwise the element is invisible. Therefore, when you disappear an element, you must set the status of the element to false as well. I assume this is the code in your getView (), and you have already defined your boolean array with the same length as the ListView elements, and true with the name "yourButtonStatusBooleanArray", after which the following changes will work for you.
holder.checkbox = (Button) view.findViewById(R.id.checkBox1); if(!yourButtonStatusBooleanArray[position]) { holder.checkbox.setVisibility(View.INVISIBLE); } holder.checkbox.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { holder.checkbox.setVisibility(View.INVISIBLE); yourButtonStatusBooleanArray[position]=false;
source share