在自定义列表视图中使用自定义循环进度条(列表视图的每一行都有一个文本视图和进度条)。进度条从等待时间减少,如倒计时,我的想法是使用 CountDownTimer ,但无法知道如何在Customized Listview中使用它。任何人都知道帮助我解决这个问题。
适配器类
public class Order_adp extends BaseAdapter {
public ArrayList<Order_Model> list;
Activity activity;
public Order_adp(Activity activity, ArrayList<Order_Model> list) {
super();
this.activity = activity;
this.list = list;
}
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return list.get(position);
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
class ViewHolder {
TextView order_number, remaining_time;
ProgressBar progressBar;
}
public View getView(final int position, View convertView, final ViewGroup parent) {
// TODO Auto-generated method stub
final ViewHolder holder;
LayoutInflater inflater = activity.getLayoutInflater();
if (convertView == null) {
convertView = inflater.inflate(R.layout.progrescustom_layout_file, null);
holder = new ViewHolder();
holder.order_number = (TextView) convertView.findViewById(R.id.textView3);
holder.progressBar = (ProgressBar) convertView.findViewById(R.id.circularProgressBar);
holder.remaining_time = (TextView) convertView.findViewById(R.id.textView1);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
float fraction = Integer.valueOf(list.get(position).getwaiting_time())*1000 / (float) Integer.valueOf(list.get(position).getwaiting_time())*1000;
holder.progressBar.setMax( (int) (fraction * 100) );
holder.progressBar.setProgress(100);
holder.order_number.setText(list.get(position).getorder_number());
/*CountDownTimer timer = new CountDownTimer(Integer.valueOf(list.get(position).getwaiting_time())*1000,1000) {
@Override
public void onTick(long millisUntilFinished) {
int secondsRemaining = (int) millisUntilFinished / 1000;
float fraction = millisUntilFinished / (float) (Integer.valueOf(list.get(position).getwaiting_time())*1000);
holder.progressBar.setProgress ( (int) (fraction * 100) );
holder.remaining_time.setText(secondsRemaining+" more");
}
@Override
public void onFinish() {
holder.remaining_time.setText("Finished");
}
}.start();
timer.start();*/
return convertView;
}
}
从缩短时间的等待时间开始显示holder.remaining_time
并更新进度条holder.progressBar
。进度条从100%
减少到0%