如何在每个列表项中显示进度条?

7
请帮我在列表项中显示进度对话框。
public class DealerSubCatListAdapter extends BaseAdapter {
        private Context context;
        private ArrayList<Image> Image;
        private LayoutInflater inflater = null;

        public DealerSubCatListAdapter(Context context, ArrayList<Image> Image) {

            this.context = context;
            this.Image = Image;
            inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);


            notifyDataSetChanged();

        }

        @Override
        public int getCount() {
            return Image.size();
        }

        @Override
        public Object getItem(int position) {
            return position;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = null;
            if (convertView == null) {
                view = inflater.inflate(R.layout.imagesubcat, null);
            } else {
                view = convertView;
            }

            TextView imagesubcat = (TextView) view.findViewById(R.id.imagesubcattv);
            // tagLine

            imagesubcat.setText(Image.get(position).image_type);

            return view;
        }

    }

所以,这是适配器展示列表项的内容。

1
请查看我的答案,它肯定会帮到你的。 - GrIsHu
4个回答

9

2
R.layout.imagesubcat中添加一个进度条,并声明一个整数数组来表示进度。
int[] progress;

在构造函数中传递进度数组。

现在在getView方法中:

progressBar.setProgress(progress[position]);

无论何时进度发生变化,都要通知适配器。

1
问题在于当多个文件正在下载时,会报告大量的进度更新,这将产生大量对notifyDataSetChanged的调用,这已经证明使按钮不响应。 - GaRRaPeTa

1
如果您真的想在每个列表项中显示进度条(虽然对我来说似乎很奇怪),您可以在R.layout.imagesubcat中声明一个进度条。
进度条的XML标签:
   <ProgressBar
   android:id="@+id/progressBar1"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   android:layout_centerInParent="true" />

1
进度对话框应该在你调用此适配器的某个地方显示。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接