奇怪的是,我的CustomBaseAdapter
错误地返回了需要膨胀的项目,等等,适配器将错误的数据显示在行上!BaseAdapter在getView()方法调用时返回错误的位置
虽然我现在用的是ViewHolder
模式,我的ListView layout_height
设置为match_parent
和无微不至我发现,以保证项目的ListView稳定,已经落实,CustomBaseAdapter
似乎没有它响应。
getView()方法
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
mItemView = convertView;
if (convertView == null) {
mItemView = mInflater.inflate(R.layout.layout_listview_row, parent, false);
holder = new ViewHolder();
//setting up the Views
mItemView.setTag(holder);
} else {
holder = (ViewHolder) mItemView.getTag();
}
//Getting the item
final MyItem item = getItem(position);
//Doing some checks on my item and then display the appropriate data.
//By saying checks i mean something like:
if(item.getSomething().equals("blabla")){
//Load some pic
}else{
//Load another pic
}
//Now when i have scrolled the list once and return back to top,
//Suddenly in Logcat i am seeing that the first row is getting matched to
//the object in the 4th position, but it doesnt display its data. It displays
//the text from the first item as it was supposed to do. But the relation between
//the first row and the item's position is like 0->4.
}
其他方法
@Override
public int getCount() {
return this.mObjects.size();
}
@Override
public MyItem getItem(int position) {
return this.mObjects.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
我从字面上搜索并尝试在谷歌的一切!似乎没有任何东西给我一个解决方案。
任何帮助,将不胜感激!让我知道你是否需要更多的代码。
采取这里看看......是的,我知道这是1H但是,值得...的https:/ /www.youtube.com/watch?v=wDBM6wVEO70 – Selvin 2014-12-05 00:32:41
我已经看过它,但无法理解我做错了什么! – Pavlos 2014-12-05 00:36:08
是的,我修正了这个问题,但给-1只是因为你猜测我可能在做某种愚蠢的检查并不公平。无论如何... – Pavlos 2014-12-05 00:51:08