Listview在使用convertview时以错误的顺序返回项目

时间:2011-12-25 11:25:01

标签: android listview baseadapter convertview

当我使用convertView时,它返回错误的视图项。它返回正确的对象,应该在这个位置。但是返回wrong view

 public View getView(int arg0, View arg1, ViewGroup arg2) {
// for (Capsule capsule : capsules) {
// Log.d(TAG, "Capsule " + capsule.getId() + " progress is " +
// capsule.getProgress());
// }
// Log.d(TAG, "Position of getView is " + arg0);
Capsule c = getItem(arg0);
Log.d(TAG, "Position of getView is " + arg0 + " capsule title is " + c.getTitle());
 if (arg1 != null) {
 ProgressBar bar = (ProgressBar)
 arg1.findViewById(R.id.item_obtained_progressbar);
 TextView date = (TextView)
 arg1.findViewById(R.id.item_obtained_dateofopen);
 if (c.getProgress() > 0) {
 bar.setVisibility(View.VISIBLE);
 date.setVisibility(View.INVISIBLE);
 bar.setProgress(c.getProgress());
 }
 return arg1;
 }
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemView = inflater.inflate(R.layout.item_obtained, null);
itemView.setPadding(0, 30, 0, 0);
ProgressBar bar = (ProgressBar) itemView.findViewById(R.id.item_obtained_progressbar);
bar.setVisibility(View.INVISIBLE);
TextView date = (TextView) itemView.findViewById(R.id.item_obtained_dateofopen);
TextView title = (TextView) itemView.findViewById(R.id.item_obtained_title);
TextView name = (TextView) itemView.findViewById(R.id.item_obtained_name);
ImageView photo = (ImageView) itemView.findViewById(R.id.item_obtained_photo);
ImageView video = (ImageView) itemView.findViewById(R.id.item_obtained_video);
date.setText(c.getSentString());
title.setText(c.getTitle());
name.setText(c.getRealname());
if (!c.hasPhoto) {
    photo.setVisibility(View.INVISIBLE);
}
if (!c.hasVideo) {
    video.setVisibility(View.INVISIBLE);
}
Log.d(TAG, "Current capsule " + c.getId() + " progress is " + c.getProgress());
if (c.getProgress() > 0) {
    bar.setVisibility(View.VISIBLE);
    date.setVisibility(View.INVISIBLE);
    bar.setProgress(c.getProgress());
}
return itemView;
}

这是我的来源。我正在从Capsule object&中检索array下载文件时更新ProgressBar。除了订单,它的效果很好。当我用convertView评论部分时,一切顺利。

0 个答案:

没有答案