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-圖片/ –