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

发布于 2024-12-22 19:47:33 字数 2147 浏览 3 评论 0原文

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

 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;
}

这是我的来源。我正在从 array 检索 Capsule 对象 &下载文件时更新 ProgressBar。除了顺序之外,它工作得很好。当我用 convertView 注释部分时,一切正常。

When i'm using convertView it returns wrong view items. It returns right object, that should be at this position. But returns 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;
}

Here is my source. I'm retrieving Capsule object from array & updating ProgressBar while downloading files. It works nice except order. When I comment part with convertView everything goes right.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文