【发布时间】:2015-12-22 14:53:46
【问题描述】:
我正在使用带有光标适配器的列表视图。当我单击此图像视图时,此列表视图在每个项目中都有一个图像视图,我更改了正在正确更改的图像视图图像,但是当我滚动列表图像视图时,它会更改为其原始视图。 注意:我正在使用光标适配器。(我知道列表视图回收并且我知道控制简单适配器中的值更改(基于模型)) 这是我的光标适配器:
@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);
}
}
});
}
【问题讨论】:
-
感谢您的回复。我知道列表视图回收,我知道如何控制简单适配器(基于模型)中的值更改,但我面临光标适配器的问题。
-
我认为问题在于,当 ListView 滚动时,bindView 被再次调用,当它被调用时,就好像它还没有被点击一样,所以图像恢复为默认值。您需要找到一种方法来标记该项目以知道要使用哪个图像。
-
这是我的问题,如何停止这种变化。在简单的适配器中(使用模型和 getview,我们可以在项目变化时更改模型,因此这种变化仍然存在)但是如何使用光标来完成。
标签: android listview android-listview cursor android-cursoradapter