我正在尝试通过遵循提供在TwoWayView链接中的示例项目来实现TwoWayView。我已经实现了所有内容,我的代码没有任何错误,但实际的列表没有被填充。通过调试,我发现适配器被正确设置,并且getItemCount方法也返回正数计数,但是另外两个重写的方法onCreateViewHolder和onBindViewHolder没有被调用。我不知道为什么它不起作用。请看下面的部分代码,感谢您的帮助。谢谢。
MyAdapter.java类
MyAdapter.java类
public class MyAdapter extends RecyclerView.Adapter < MyViewHolder > {
private MySimpleCursorAdapter mCursor;
//some other private fields here
public MyAdapter(Context context, Cursor c, int resourceId, ViewType viewType, String containerId) {
mCursor = new MySimpleCursorAdapter(a1,a2,a3,a4,a5,a6); //Passed necessary arguments
....
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
Log.w("onCreateViewHolder", "--------->executed"); //Line not executed
final View view = mCursor.newView(mContext, mCursor.getCursor(), parent);
return new MyViewHolder(view);
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
Log.w("onBindViewHolder", "--------->executed"); //Line not executed
mCursor.bindView(holder.itemView, mContext, mCursor.getCursor());
}
@Override
public int getItemCount() {
Log.w("count", Integer.toString(mCursor.getCount())); //This is executed
return mCursor.getCount();
}
private class MySimpleCursorAdapter extends SimpleCursorAdapter {
public MySimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) {
super(context, layout, c, from, to, flags);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View view = mLayoutInflater.inflate(mLayoutToInflate, null);
....
return view;
}
@Override
public void bindView(final View view, Context context, Cursor cursor) {
//Implemented this method for inflating all subviews inside each item of the list
}
}
}
注意:我已经浏览了类似的问题,但那里提供的答案与我的问题不相关,因为我的RecyclerView
不在ScrollView
内,并且getItemCount
返回正数计数。