Listviewは単一のItemレイアウトとlistviewを更新する.getLastVisiblePosition()=-1問題の解決
private Handler downHandler = new Handler(){
public void handleMessage(Message msg) {
if(clickPosition>=lvDownLoad.getFirstVisiblePosition() &&
clickPosition <= lvDownLoad.getLastVisiblePosition()) {
int positionInListView = clickPosition - lvDownLoad.getFirstVisiblePosition();
ProgressBar pb = (ProgressBar) lvDownLoad.getChildAt(positionInListView)
.findViewById(R.id.pb_download);
TextView tv = (TextView) lvDownLoad.getChildAt(positionInListView)
.findViewById(R.id.tv_download_state);
switch (msg.what) {
case 0: //
pb.setVisibility(View.VISIBLE);
tv.setText(" ");
break;
case 1: //
pb.setProgress((int)(downLoadFileSize/fileSize*100));
break;
case 2: //
pb.setVisibility(View.INVISIBLE);
tv.setText(" ");
break;
}
}
};
};
コード:
lvDownLoad.post(new Runnable() {
@Override
public void run() {
for(int i=0;i
if(i >= lvDownLoad.getFirstVisiblePosition() &&
i <= lvDownLoad.getLastVisiblePosition()){
int ii = i - lvDownLoad.getFirstVisiblePosition();
ProgressBar pb = (ProgressBar)lvDownLoad.getChildAt(ii)
.findViewById(R.id.pb_download);
TextView tv = (TextView) lvDownLoad.getChildAt(ii)
.findViewById(R.id.tv_download_state);
if(GetFileSizeUtil.fileIsExists( //
Environment.getExternalStorageDirectory().getPath()
+"/zcdownloadFile/"+files.get(i).getFileName())){
pb.setVisibility(View.INVISIBLE);
tv.setText(" ");
}else{ //
pb.setVisibility(View.VISIBLE);
tv.setText(" ");
}
}
}
}
});