0

有一种情况,getItemCountAndroid RecycerView4.0.3 ( ) 不调用适配器IceCreamSandwich。所有其他 API 版本都没有任何问题。我按如下方式创建我的适配器:

Log.i(LOG_TAG, "array size = " + myArray.size());
adapter = new MyListAdapter(context, myArray, this);
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(adapter);

我插入了Log.i以确认数组中有一个元素,它确实存在。在RecyclerView适配器的构造函数中,我有:

public MyListAdapter(Context context, List<dataModel> data, MyListener listener) {
    this.context = context;
    this.mData = data;
    this.mInflater = LayoutInflater.from(context);
    this.mListener = listener;

    Log.i(LOG_TAG, "data size = " + this.mData.size());
}

并且构造函数中的数据大小不为空。当适配器被创建并设置为 a 时,什么可能导致getItemCount不被调用RecyclerView?同样,这仅发生在IceCreamSandwichAPI 上,所有其他都可以正常工作。

4

0 回答 0