Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用RecyclerView显示每个项目,每个项目带有一个按钮,该按钮应启动不同的RecyclerView 议题大纲_Java_Android_Android Layout_Android Fragments - Fatal编程技术网

Java 使用RecyclerView显示每个项目,每个项目带有一个按钮,该按钮应启动不同的RecyclerView 议题大纲

Java 使用RecyclerView显示每个项目,每个项目带有一个按钮,该按钮应启动不同的RecyclerView 议题大纲,java,android,android-layout,android-fragments,Java,Android,Android Layout,Android Fragments,错误:未连接适配器;跳过布局 调查显示,从未调用新RecyclerView的onBindViewHolder 我已经搜索并尝试了许多替代方案,但到目前为止运气不佳。我曾尝试使用一个Recycleview来处理这两种片段类型,但最终都遇到了相同的问题 第一个RecyclerView按预期工作并显示片段项,每个片段项都有一个按钮,可以打开一个新的RecyclerView,其中列出了来自不同数据集(以及不同格式)的项 我对安卓系统还很陌生,所以如果您能提供任何帮助,我将不胜感激 onBindViewH

错误:未连接适配器;跳过布局

调查显示,从未调用新RecyclerView的onBindViewHolder

我已经搜索并尝试了许多替代方案,但到目前为止运气不佳。我曾尝试使用一个Recycleview来处理这两种片段类型,但最终都遇到了相同的问题

第一个RecyclerView按预期工作并显示片段项,每个片段项都有一个按钮,可以打开一个新的RecyclerView,其中列出了来自不同数据集(以及不同格式)的项

我对安卓系统还很陌生,所以如果您能提供任何帮助,我将不胜感激

onBindViewHolder中的onClick代码 一旦创建新活动 为新片段创建OnCreate
@覆盖
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
recyclerView=新的recyclerView(getContext());
recyclerView.findViewById(R.id.list2);
Log.i(Configuration.TAG,“事件列表片段onCreate”);
checkFeed=TheEvents.getInstance();
Bundle extras=getActivity().getIntent().getExtras();
String eventID=extras.getString(“eventID”);
int eventPosition=extras.getInt(“eventPosition”);
System.out.println(“这是eventid”+eventid+”是位置:+eventPosition);
列表提要=checkFeed.getItemAt(eventPosition).getChecklists();
setLayoutManager(新的LinearLayoutManager(getContext());
适配器=新的CheckListRecycleServiceAdapter(提要,mlister);
对于(int i=0;i
RecyclerView列表布局

列表项布局

单帧布局


能否请您将片段代码放在“onCreateView”而不是“onCreate”中?我已将所有代码从“onCreate”移到了行上方的“onCreateView”:视图=充气机。充气(R.layout.fragment\u checklist\u list,container,false);然而,它给出了相同的结果。你喜欢这样做吗?如果你仍然有相同的错误,请用logcat中的错误更新你的问题。我现在已经解决了这个问题。我已经对项目进行了重构,以使用单个回收器视图。当我最初尝试这种方法时,您关于移动到onCreateView的建议是谜题中缺少的部分。目前工作的最后期限很紧,但计划在我有空的时候上传解决方案。你能把片段代码放在'onCreateView'而不是'onCreate'中吗?我已经把所有代码从'onCreate'移到了'onCreateView'的上方:View View=inflater.inflate(R.layout.fragment\u checklist\u list,container,false);然而,它给出了相同的结果。你喜欢这样做吗?如果你仍然有相同的错误,请用logcat中的错误更新你的问题。我现在已经解决了这个问题。我已经对项目进行了重构,以使用单个回收器视图。当我最初尝试这种方法时,您关于移动到onCreateView的建议是谜题中缺少的部分。目前工作的最后期限很紧,但计划在我有空闲时间时上传解决方案。
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" />