getView位置未正确检索

时间:2015-09-16 19:14:08

标签: android listview android-listview baseadapter

我有一个BaseAdapter如下:

public class OrderAdapter extends BaseAdapter {
private final Context mContext;
private Handler mHandler;
private List<Order> mOrders = Collections.emptyList();
private Message msg;
private int counter;

public OrderAdapter(Context context, List<Order> objects) {
    ThreadPreconditions.checkOnMainThread();
    this.mContext = context;
    this.mOrders = objects;
    notifyDataSetChanged();
}
public OrderAdapter(Context context, List<Order> objects, Handler handler) {
    ThreadPreconditions.checkOnMainThread();
    this.mContext = context;
    this.mOrders = objects;
    this.mHandler = handler;
    notifyDataSetChanged();
}

public void updateOrders(List<Order> bananaPhones) {
    ThreadPreconditions.checkOnMainThread();
    this.mOrders = bananaPhones;
    notifyDataSetChanged();
}

@Override
public int getCount() {
    return mOrders.size();
}

@Override
public Order getItem(int position) {
    return mOrders.get(position);
}

// getItemId() is often useless, I think this should be the default
// implementation in BaseAdapter
@Override
public long getItemId(int position) {
    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent){
    msg = Message.obtain();
    if (convertView == null){
        convertView = LayoutInflater.from(mContext).inflate(R.layout.order_row_item, parent, false);
    }
    msg.what = position;
    msg.obj = convertView;
    mHandler.sendMessage(msg);
    return convertView;
}


}

在我的活动中,我有一个处理程序,它异步地接收和更改行的值。问题是:&#34;位置&#34;由getView检索不正确,它实际上从0-4开始随机出现。在调试会话中,我发现适配器具有正确的项目,它只是使视图错误。我的listView不在scrollView上,它的高度是fill_parent,并且适配器上没有asyncTask,所以即使创建新的thead也是由活动完成的(我认为这是重置数字,但那是不是这样的。)

现在已经坚持了2天,任何帮助都会非常感激。

1 个答案:

答案 0 :(得分:1)