android进度按钮
⑴ android中如何实现在自定义的listview中点击一个按钮一个对应的进度条加载求高手解答
private class Adatpter extends BaseAdapter{
@Override
public int getCount() {
return 5;
}
@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 position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = getLayoutInflater().inflate(R.layout.test_list_try_item, null);
Button btn = (Button) view.findViewById(R.id.test_list_try_item_button);
btn.setOnClickListener(new OnBtnClickListener((ProgressBar) view.findViewById(R.id.test_list_try_item_progressbar)));
return view;
}
}
private class OnBtnClickListener implements OnClickListener{
private int progress = 0;
private ProgressBar bar = null;
public OnBtnClickListener(ProgressBar bar){
this.bar = bar;
}
@Override
public void onClick(View v) {
if(null != bar)
bar.setProgress(progress);
progress = (progress + 10)%100;
}
}
不知道你要的是不是这样的效果。随便写的,能用,希望能帮到你
⑵ android编程里如何使用按钮来增加和减少进度条的进度
java">//这个是增加的,把这看懂,减的也就会了
packagecom.example.progressbardemo;
importandroid.app.Activity;
importandroid.os.Bundle;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.widget.Button;
importandroid.widget.ProgressBar;
{
privateProgressBarone;
privateButtonbutton;
privateinti=0;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
one=(ProgressBar)findViewById(R.id.progressBar2);
button=(Button)findViewById(R.id.button1);
button.setOnClickListener(newOnClickListener(){
@Override
publicvoidonClick(Viewarg0){
if(i==0){
one.setVisibility(View.VISIBLE);
}
elseif(i<one.getMax())
{
one.setProgress(i);
}
else
{
one.setVisibility(View.GONE);
i=0;
}
i+=5;
}
});
}
}