getView 位置未正确检索

getView position is not retrieving the correctly

我有一个 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;
}


}

在我的 activity 上,我有一个处理程序可以异步接收和更改行的值。问题是:getView 得到的 "position" 是不正确的,它实际上是从 0-4 随机的。在调试会话中,我发现适配器具有正确的项,只是视图出错了。我的 listView 不在 scrollView 上,它的高度是 fill_parent 并且适配器上没有 asyncTask,所以即使创建新的 thead 也是由 activity 完成的(我认为这是重置数字,但事实并非如此)。

现在已经坚持了 2 天,任何帮助将不胜感激。

在 getView() 中使用 ViewHolder

看到这个linkhttps://www.caveofprogramming.com/guest-posts/custom-listview-with-imageview-and-textview-in-android.html