如何使用适配器类在ListView中创建ProgressBar?

时间:2012-08-01 14:26:08

标签: android android-widget android-listview

我曾尝试在ProgressBar中使用ListView,我曾使用适配器类在ProgressBar中显示文本和ListView,但我无法得到它。< / p>

public class ProgressBarActivity extends Activity {

    EditText edtTxt;
    Button btn;
    ListView lstExample;
    String txt;
    progressAdapter adapter;
    ArrayList<String> adap;

    protected void onCreate(Bundle icicle)
    {
        super.onCreate(icicle);

        setContentView(R.layout.main);

        edtTxt=(EditText) findViewById(R.id.edtText);
        btn=(Button) findViewById(R.id.btn);
        adap=new ArrayList<String>();
        lstExample=(ListView) findViewById(R.id.listView1);
             btn.setOnClickListener(new OnClickListener() 
             {

                @Override
                public void onClick(View arg0) 
                {
                    txt=edtTxt.getText().toString();
                    if(txt.equals(""))
                    {
                        Toast.makeText(getApplicationContext(), "Enter the text", Toast.LENGTH_LONG).show();
                    }
                    else
                    {
                        adap.add(txt);
                        String[] arr=adap.toArray(new String[adap.size()]);
                        adapter=new progressAdapter(ProgressBarActivity.this, arr);
                        lstExample.setAdapter(adapter);
                    }
                }
            });      

    }

这是我的适配器类:

public class progressAdapter extends BaseAdapter
{
    public  Activity activity;
    String[] str;
    String comment;
    LayoutInflater inflater=null;
    int progressBarStatus=0;
    private Handler progressBarHandler = new Handler();
    TextView t1;

    public progressAdapter(ProgressBarActivity sam,String[] txt) 
    {
        activity=sam;
        str=txt;

        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() 
    {
        // TODO Auto-generated method stub
        return str.length;
    }

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

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

    @Override
    public View getView( int position,  View convertView, ViewGroup parent) 
    {
        View  vi=convertView;
            if(convertView==null)
                vi = inflater.inflate(R.layout.progress,null);
            t1=(TextView)vi.findViewById(R.id.textView1);
            final ProgressBar pro=(ProgressBar)vi.findViewById(R.id.progressBar1);

            comment=str[position];
            pro.setVisibility(vi.VISIBLE);

            t1.setText(comment);

        return vi;
    }
}

它正在运行,但它正在所有ListView中运行。

0 个答案:

没有答案