我遇到問題ListView
。適配器的下面的代碼:Android ListView顯示錯誤的位置
public class AdapterListViewEncyclopedia extends ArrayAdapter<Apple> {
private int layoutResourceId;
private Context context;
private List<Apple> data;
private CellHolder holder;
public AdapterListViewEncyclopedia(Context context, int layoutResourceId, List<Apple> data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
}
static class CellHolder
{
ImageView imageApple;
TextView tvCellAppleName;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent)
{
View row = convertView;
if(row == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new CellHolder();
holder.imageApple = (ImageView) row.findViewById(R.id.imageApple);
holder.tvCellAppleName = (TextView)row.findViewById(R.id.tvAppleName);
ImageLoader imageLoader = ImageLoader.getInstance();
imageLoader.displayImage(InterfaceConfig.serverURL+data.get(position).getImageURL(), holder.imageApple);
holder.tvCellAppleName.setText(data.get(position).getName());
System.out.println(position);
row.setTag(holder);
}
else
{
holder = (CellHolder)row.getTag();
}
return row;
}
}
的主要問題:
1.I有10個數據ArrayAdapter<Apple>
,當我打開網頁,ListView
和我打印位置代碼System.out.println
,代碼顯示0 ,1,2,3,4,5,0 2.當我滾動ListView
,頂部和底部隱藏是隨機的位置。
任何人都可以幫我解決我的問題嗎?
閱讀代碼...當您設置文本?只有... – Selvin
我也不知道爲什麼這些人使用那個臭名昭着的視圖持有人......它給與它的問題相比有多少幫助? – pskink
@selvin:對不起,我已經更新了代碼。 – Michael