Listview有一个默认图像,我将其替换为另一图像,当图像被选中时(如下所示 - onClickListener)。问题是当listView熄灭并且返回到View中时,替换deault图像的图像会恢复为默认图像。当Listview滚动时,自定义Listview中的图像正在被取消设置
public class BookViewCustomList extends ArrayAdapter<String>{
private final Activity context;
private final ArrayList<String> chapter;
private final ArrayList<String> verse;
private final ArrayList<String> content;
private final Integer[] imageId;
public BookViewCustomList(Activity context, ArrayList<String> chapter, ArrayList<String> verse, Integer[] imageId, ArrayList<String> content) {
super(context, R.layout.custom_book_view_layout, chapter);
this.context = context;
this.chapter = chapter;
this.verse = verse;
this.imageId = imageId;
this.content = content;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView = inflater.inflate(R.layout.custom_book_view_layout, null, true);
TextView txtChapter = (TextView) rowView.findViewById(R.id.textViewChapter);
txtChapter.setText(chapter.get(position));
TextView txtVerse = (TextView) rowView.findViewById(R.id.textViewVerse);
txtVerse.setText(verse.get(position));
//ImageView imageViewBookmark = (ImageView) rowView.findViewById(R.id.imageButtonBookmark);
//imageViewBookmark.setImageResource(imageId[position]);
TextView txtContent = (TextView) rowView.findViewById(R.id.textViewContent);
txtContent.setText(content.get(position));
final ImageView imgView = (ImageView) rowView.findViewById(R.id.imageViewBookmark);
imgView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
imgView.setImageResource(R.drawable.bookmark_blue);
}
});
return rowView;
}
}
那么如何留住已经作出了改变?谢谢!
使用视图架模式http://codehenge.net/blog/2011/06/android-development-tutorial-asynchronous-lazy-loading-and-caching-of-listview-图片/ –