错误:没有连接适配器;跳过布局。
调查显示,从不调用新的RecyclerView的onBindViewHolder。
我已经搜索并尝试了许多替代解决方案但到目前为止没有运气。我尝试使用一个Recycleview来处理这两种片段类型,但结果却出现了同样的问题。
第一个RecyclerView按预期工作并显示片段项,它们每个都有一个按钮,可以打开一个新的RecyclerView,列出来自不同数据集的项目(并使用不同的格式)。
我对android很新,所以感谢您提供的任何帮助。
holder.checklistButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Context context = view.getContext();
final Intent intent = new Intent(context, ChecklistActivity.class);
intent.putExtra("EVENTPOSITION",mValues.indexOf(holder.mItem));
intent.putExtra("EVENTID", holder.mItem.getEventID().toString());
context.startActivity(intent);
}`
setContentView(R.layout.activity_single_fragment);
FragmentManager fm = this.getSupportFragmentManager();
Fragment fragment = fm.findFragmentById(R.id.fragmentContainer);
if (fragment==null){
fragment = new ChecklistFragment(); fm.beginTransaction().replace(R.id.fragmentContainer,fragment).addToBackStack(null).commit();
fm.beginTransaction().add(R.id.fragmentContainer,fragment).commit();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
recyclerView = new RecyclerView(getContext());
recyclerView.findViewById(R.id.list2);
Log.i(Configuration.TAG, "Event List Fragment onCreate");
checkFeed = TheEvents.getInstance();
Bundle extras = getActivity().getIntent().getExtras();
String eventID = extras.getString("EVENTID");
int eventPosition = extras.getInt("EVENTPOSITION");
System.out.println("this is the eventid " + eventID + " is position: " + eventPosition);
List<Checklist> feed = checkFeed.getItemAt(eventPosition).getChecklists();
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
adapter = new ChecklistRecyclerViewAdapter(feed, mListener);
for (int i = 0; i < feed.size(); i++) {
System.out.println("this is the checklists " + feed.get(i).getChecklistName());
}
System.out.println("CREATED ADAPTER: " + adapter);
recyclerView.setAdapter(adapter);
}
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/list2"
android:name="read.checklist.ChecklistFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
app:layoutManager="LinearLayoutManager"
tools:context="read.checklist.ChecklistFragment"
tools:listitem="@layout/fragment_checklists_item" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/list2item"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<TextView
android:id="@+id/checklistName"
style="@style/seventName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/checklist_name" />
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:layout_gravity="bottom|right"
android:layout_margin="30dp"
app:fabSize="normal"
app:srcCompat="@android:drawable/ic_menu_add"
android:id="@+id/fabAddEvent" />