で使おうとしてProgressBar
、ListView
アダプタクラスを使ってテキストを表示したり、ProgressBar
inListView
で使ったりしましたが、取得できませんでした。
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
.