If you want to hide the ImageView
by default and make is visible after clicking on the list position, Simply set the ImageView
to hidden at the beginning then make it visible after the list item click.
//first make a int that holds the clicked position,
int current_position = -1;
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ImageView ivDelete = (ImageView) convertView.findViewById(R.id.imageView2);
// check if the current_position has been changed once
// and it matches the position in list
if (position > 0 && position == current_position){
ivDelete.setVisibity(View.VISIBLE);
}
else {
ivDelete.setVisibity(View.GONE);
}
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ivDelete.setVisibitiy(View.VISIBLE);
// set the current_position to list position
current_position = position;
}
});
}
Now every-time you delete a list item set the current_position = -1;
This will hide the ImageView
again and won’t display until you click on a list item again.
2
solved Changing the visibility of a Image View on touch Row of ListView [closed]