在我的情况下,我有一个列表视图,点击一个项目就会出现一个imageview。但如果我向下或向上滚动,图像视图将消失。我怎样才能拯救"观点的状态? 感谢
- 编辑 - 这是我的适配器:
public class FeedListAdapterTab2 extends BaseAdapter {
private Activity activity;
private LayoutInflater inflater;
private List<FeedItemAbos> feedItems;
com.android.volley.toolbox.ImageLoader imageLoader = AppController.getInstance().getImageLoader();
View.OnClickListener onClickListener;
JSONParser jsonParser = new JSONParser();
FeedItemAbos item;
private long timestampLastClick;
private long doubleClickQualificationSpanInMillis;
private static final long DEFAULT_QUALIFICATION_SPAN = 200;
String quotesID;
TextView textViewQuotations;
//UNIVERSAL
private DisplayImageOptions options, optionsFeedImage;
private ImageLoadingListener animateFirstListener = new AnimateFirstDisplayListener();
public FeedListAdapterTab2(Activity activity, List<FeedItemAbos> feedItems, View.OnClickListener onClickListener) {
this.activity = activity;
this.feedItems = feedItems;
this.onClickListener = onClickListener;
//UNIVERSAL
options = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.ic_stub)
.showImageForEmptyUri(R.drawable.ic_empty)
.showImageOnFail(R.drawable.ic_error)
.cacheInMemory(true)
.cacheOnDisk(true)
.displayer(new CircleBitmapDisplayer(Color.WHITE, 5))
.build();
//UNIVERSAL
optionsFeedImage = new DisplayImageOptions.Builder()
.cacheInMemory(true)
.cacheOnDisk(true)
.build();
}
@Override
public int getCount() {
return feedItems.size();
}
@Override
public Object getItem(int location) {
return feedItems.get(location);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (inflater == null)
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
convertView = inflater.inflate(R.layout.feed_item, null);
if (imageLoader == null)
imageLoader = AppController.getInstance().getImageLoader();
final ImageView imageViewLike = (ImageView) convertView.
findViewById(R.id.imageViewLike);
try {
item = feedItems.get(position);
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if ((SystemClock.elapsedRealtime() - timestampLastClick) < doubleClickQualificationSpanInMillis) {
Log.e("DOUBLE", "CLICK");
timestampLastClick = 0;
ID = String.valueOf(v.getId());
timestampLastClick = SystemClock.elapsedRealtime();
//
imageViewLike.setVisibility(View.VISIBLE);
Log.e("id", "nice " + v.getId());
}
});
}
return convertView;
}
在&#34;双击&#34;在转换视图上,所以列表视图的视图出现了一个imageview。但是如果视图没有再次显示,则imageview会消失。
答案 0 :(得分:1)
列表适配器(ListAdapter或子类)应保持每个项目的状态。表示项目的视图在不再可见时会被销毁或回收。 当项目再次可见时,将再次调用ListAdapter.getView()。