Android GridView更新进度条,同时滚动更新griditem中的另一个进度条

时间:2015-02-16 08:56:06

标签: android

我正在创建一个网格视图,并且每个网格项都有图像下载和进度条,当用户点击图像时必须下载并需要显示进度条。显示进度条和下载图像正在工作但滚动gridview时它更新了其他一些网格项进度条(只有进度条正在更新而不下载图像)

下面提到代码

MyAdapater.java:

class MyAdapater extends BaseAdapter{

Context mContext;
public ArrayList<String> al;
public ArrayList<String> alavaliproducts;
public MyAdapater(Context context,ArrayList<String> al,ArrayList<String> alavaliproducts){
    mContext=context;
    this.al= al;
    this.alavaliproducts=alavaliproducts;
}
@Override
public int getCount() {
    // TODO Auto-generated method stub
    return al.size();
}

@Override
public Object getItem(int position) {
    // TODO Auto-generated method stub
    return null;
}

@Override
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    View row;
    if(convertView==null){
         LayoutInflater inflater = (LayoutInflater)    mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE );
         row = inflater.inflate(R.layout.grid_item, parent, false);
    }else{
        row=convertView;
    }

    TextView textview1=(TextView) row.findViewById(R.id.textView1); //"@+id/tvtitle"
    TextView textview2=(TextView) row.findViewById(R.id.tvtitle); 
    ImageView imvdownlond=(ImageView) row.findViewById(R.id.imageView1);
    ProgressBar progressdownload=(ProgressBar) row.findViewById(R.id.progressbar_download);
    String name=al.get(position);
    Log.e("adapter", "my files "+alavaliproducts);
    if(alavaliproducts.contains(name)){
        imvdownlond.setVisibility(View.GONE);
        Log.e("adapter", name+"  download status completed");
    }else{
        //imvdownlond.setVisibility(View.VISIBLE);
        Log.e("adapter", name+" not download");

    }
    textview1.setText(name);
    textview2.setText(name);

    return row;
}

}

点击网格项,我们将执行以下代码

private void gridview() {
    // TODO Auto-generated method stub
    gridview.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            // TODO Auto-generated method stub
            TextView tvtitle=(TextView) view.findViewById(R.id.tvtitle);
            //imgproduct

            Log.e("process name", "view position= "+ gridview.getPositionForView(view));
            Log.e("process name", "position = "+ position);
            ImageView imvdownlond=(ImageView) view.findViewById(R.id.imageView1);
            int visibility=imvdownlond.getVisibility();
              if(visibility==View.VISIBLE){
                imvdownlond.setVisibility(View.GONE);

                  ProgressBar   progressBar1 = (ProgressBar)view.findViewById(R.id.progressbar_download);
                   progressBar1.setVisibility(View.VISIBLE);

                 String url = "http://upload.wikimedia.org/wikipedia/commons/0/05/Sna_large.png";

                GrabURL myasync= new GrabURL(tvtitle.getText().toString(),progressBar1);
                 StartAsyncTaskInParallel(myasync, url,tvtitle.getText().toString()+".png");

              }else {

              }


        }
    });
}

0 个答案:

没有答案