我正在使用一個ListView的Android應用程序,其中每一行都包含一個文本視圖和一個進度條。除非用戶必須滾動長列表,否則事情將順利進行。滾動瀏覽ListBar的ProgressBars
ProgressBars開始採用其他ProgressBars的進度,但屏幕上當前不可見。
據我所知,這是一個源於GetView實現的常見問題,但我想知道採用ProgressBars時採取的最佳措施是什麼。
GetView:
public View getView(int position, View convertView, ViewGroup parent){
View row = convertView;
ViewWrapper wrapper;
ProgressBar myProgressBar;
int initProgress = myData.get(position).getProgress();
if (row == null){
LayoutInflater inflater = context.getLayoutInflater();
row = inflater.inflate(R.layout.row, null);
wrapper = new ViewWrapper(row);
row.setTag(wrapper);
}
else{
wrapper = (ViewWrapper)row.getTag();
}
RowModel model = getModel(position);
wrapper.getPid().setText(model.toString());
myProgressBar = wrapper.getProgressBar();
myProgressBar.setProgress(initProgress);
myProgressBar.setMax(100);
myProgressBar.setTag(new Integer(position));
return row;
}
ViewWrapper:
public class ViewWrapper {
View base;
TextView pid = null;
ProgressBar pb= null;
ViewWrapper(View base){
this.base = base;
}
TextView getPid(){
if(pid == null){
pid = (TextView)base.findViewById(R.id.pid);
}
return(pid);
}
ProgressBar getProgressBar(){
if(pb== null){
pb= (ProgressBar)base.findViewById(R.id.progressbar);
}
return(pb);
}
}
看來這個問題涉及到:因爲進度開始得到回收的進度的行爲
myProgressBar = wrapper.getProgressBar();
。但是,我希望它有自己的行爲。
減輕這種情況的最佳方法是什麼?謝謝。