I am using a listview with cursor adapter.This listview has a imageview in each item when i click on this image view i change the imageview image which is changing properly but when i scroll my list imageview changes to its orignal view. Note : i am using cursor adapter.(I know about listview recycling and i know to to control value change in simple adapter(model based)) Here is my cursor adapter :
@Override
public void bindView(View view, final Context context, Cursor cursor) {
spotsImage = (SimpleDraweeView) view.findViewById(R.id.spotsImage);
ivFavourite = (ImageView) view.findViewById(R.id.favouriteButton);
ivFavourite.setTag(cursor.getString(cursor.getColumnIndex(Constants.PEEP_ID))+"tag"+cursor.getInt(cursor.getColumnIndex(Constants.PEEP_STATUS)));
spotsTitle = (TextView) view.findViewById(R.id.titleTextView);
followerscount = (TextView) view.findViewById(R.id.distanceTextView);
spotsTitle.setText(cursor.getString(cursor.getColumnIndex(Constants.PEEP_NAME)));
Uri uri = Uri.parse(cursor.getString(cursor.getColumnIndex(Constants.PEEP_PROFILE)));
spotsImage.setImageURI(uri);
count = cursor.getInt(cursor.getColumnIndex(Constants.PEEP_FOLLOWER_COUNT));
if (count > 1){
followerscount.setVisibility(View.VISIBLE);
followerscount.setText(count+" followers");
}
else if (count == 1){
followerscount.setVisibility(View.VISIBLE);
followerscount.setText(count+" follower");
}
else {
followerscount.setVisibility(View.INVISIBLE);
}
if (cursor.getInt(cursor.getColumnIndex(Constants.PEEP_STATUS)) == 1) {
ivFavourite
.setImageResource(R.drawable.favourites_tapped);
} else {
ivFavourite.setImageResource(R.drawable.favourites);
}
ivFavourite.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
String [] Tags = ((String) v.getTag()).split("tag");
if (Tags[1].equals("1")) {
((ImageView) v).setImageResource(R.drawable.favourites);
}
else {
((ImageView) v).setImageResource(R.drawable.favourites_tapped);
}
}
});
}