在ListView的每个项目中显示ProgressBar

时间:2011-02-22 10:29:03

标签: android listview progress-bar

我想为ProgressBar

的每个项目添加ListView

我正在向ListView添加适配器

RankAdapter adapter=new RankAdapter(model);
list.setAdapter(adapter);

RankAdapterRankHolder类如下

class RankAdapter extends CursorAdapter {
    RankAdapter(Cursor c) {
        super(RankNew.this, c);
    }

    @Override
    public void bindView(View row, Context arg1, Cursor c) {
        // TODO Auto-generated method stub

        RankHolder holder = (RankHolder) row.getTag();

        holder.populateForm(c, helper);
    }

    @Override
    public View newView(Context ctxt, Cursor c, ViewGroup parent) {
        LayoutInflater inflater = getLayoutInflater();
        View row = inflater.inflate(R.layout.rankvalues, parent, false);

        RankHolder holder = new RankHolder(row);
        row.setTag(holder);

        return row;
    }
}

class RankHolder {

    private TextView url = null;
    private TextView googletext = null;
    private TextView alexatext = null;
    private View row = null;

    RankHolder(View row) {

        this.row = row;
        url = (TextView) row.findViewById(R.id.newrankurl);
        googletext = (TextView) row.findViewById(R.id.newrankgoogle);
        alexatext = (TextView) row.findViewById(R.id.newrankalexa);
    }

    void populateForm(final Cursor c, final RankHelper helper) {
        url.setText(helper.getUrl(c));
        googletext.setText(helper.getGoogle(c));
        alexatext.setText(helper.getAlexa(c));
    }
}

2 个答案:

答案 0 :(得分:1)

将ProgressBar添加到Xml中 并在java文件中这样做

class RankAdapter extends CursorAdapter
{

   RankAdapter(Cursor c){
        super(RankNew.this,c);
   }

@Override
public void bindView(View row, Context arg1,final Cursor c) {
    // TODO Auto-generated method stub

    final RankHolder holder=(RankHolder)row.getTag();
    holder.populateForm(c,helper);
}

@Override
public View newView(Context ctxt, Cursor c, ViewGroup parent) {
    LayoutInflater inflater=getLayoutInflater();
    View row=inflater.inflate(R.layout.rankvalues,parent,false);
    RankHolder holder=new RankHolder(row);
    dialogmain.dismiss();
    row.setTag(holder);
    return row;
    }
}




class RankHolder{
    private TextView url=null;
    private TextView googletext=null;
    private TextView alexatext=null;
    private View row=null;
    private ProgressBar mSpinner=null;

    RankHolder(View row){
        this.row=row;
        mSpinner =(ProgressBar)row.findViewById(R.id.progress);        
        mSpinner.setIndeterminate(true);
        mSpinner.setVisibility(View.VISIBLE);
        url=(TextView)row.findViewById(R.id.newrankurl);
        googletext=(TextView)row.findViewById(R.id.newrankgoogle);
        alexatext=(TextView)row.findViewById(R.id.newrankalexa);
    }

    void populateForm(final Cursor c,final RankHelper helper){
        new Thread(){
            public void run(){
                try{
                    Thread.sleep(300);
                }catch(Exception e){
                }
                thhandler.sendEmptyMessage(0);
            }
        }.start();
        thhandler=new Handler(){
            @Override
            public void handleMessage(Message msg){
                super.handleMessage(msg);
                mSpinner.setVisibility(View.INVISIBLE);
            }
        };
        url.setText(helper.getUrl(c));
        if(flag==0){
            updateValues(helper.getUrl(c).toString());
        }
        googletext.setText(helper.getGoogle(c));
        alexatext.setText(helper.getAlexa(c));
    }
}

答案 1 :(得分:0)

尝试在ProgressBar xml文件中添加R.layout.rankvalues,只需在不再需要时隐藏视图。