這是我的自定義適配器代碼 我在FrameLayout中有一個imageView和一個progressbar。我想在圖片下載完成後隱藏進度條。我正在從網絡服務下載圖片。 finishImg()方法在圖像下載後調用。無法使進度條在列表視圖中隱藏
public class CustomAdapter extends BaseAdapter {
Context mContext;
ArrayList<ManagePartResponse> partList;
LayoutInflater mInflater;
static ViewHolder vh;
public CustomAdapter(Context context, ArrayList<ManagePartResponse> itemList) {
mContext = context;
partList = itemList;
mInflater = LayoutInflater.from(context);
}
public CustomAdapter(ManagePartListActivity managePartListActivity,
ArrayList<ManagePartResponse> list) {
// TODO Auto-generated constructor stub
}
public CustomAdapter() {
}
static class ViewHolder {
TextView make_tv, model_tv, partName_tv, partId_tv, year_tv;
ImageView imageView;
ProgressBar pb;
}
public int getCount() {
// TODO Auto-generated method stub
return partList.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if (convertView == null) {
vh = new ViewHolder();
convertView = mInflater.inflate(R.layout.row_3, parent, false);
vh.make_tv = (TextView) convertView.findViewById(R.id.makeId);
vh.model_tv = (TextView) convertView.findViewById(R.id.modelId);
vh.partName_tv = (TextView) convertView
.findViewById(R.id.partNameId);
vh.partId_tv = (TextView) convertView.findViewById(R.id.partId);
vh.year_tv = (TextView) convertView.findViewById(R.id.yearId);
vh.imageView = (ImageView) convertView
.findViewById(R.id.imageView1);
vh.pb = (ProgressBar) convertView.findViewById(R.id.progressBar1);
convertView.setTag(vh);
} else {
vh = (ViewHolder) convertView.getTag();
}
ManagePartResponse objBean = partList.get(position);
vh.make_tv.setText(objBean.getMake());
vh.model_tv.setText(objBean.getModel());
vh.partName_tv.setText(objBean.getPartName());
vh.year_tv.setText(objBean.getYear());
vh.partId_tv.setText(objBean.getStockref());
vh.imageView.setImageBitmap(objBean.getImage());
return convertView;
}
public static void finishImg() {
vh.pb.setVisibility(View.INVISIBLE);
vh.pb.setVisibility(View.GONE);
System.out.println("progress bar should be invisible");
}
}
加布是正確的,以獲得更多關於列表視圖閱讀此博客: http://mindfiremobile.wordpress.com/2014/03/27/optimized-listview-具有偵聽器內最行項/ –