回收站视图onClick产生另一个回收站视图

时间:2020-08-30 20:27:41

标签: java android android-intent android-recyclerview

从另一个回收者视图中单击容器视图后,我试图启动新的回收者视图。基本上,我在“ NBA_Adapter”中以回收者视图的形式列出了NBA球队名单;单击每个团队后,它将带用户到另一个回收者视图,显示团队中的球员。我正在尝试使用两个扩展回收器视图的类来做到这一点。问题是我无法启动第二个类,我怀疑是因为第二个类没有扩展“ AppCompatActivity”,而是扩展了RecyclerView,清单文件要求我这样做,因为它无法识别我的第二个类。 清单如下:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.nba">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".Second_Adapter">
         <intent-filter>
             <action android:name="android.intent.action.SEND"/>
             <category android:name="android.intent.category.DEFAULT" />

         </intent-filter>
</activity>
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-permission android:name="android.permission.INTERNET" />
</manifest>

下面的主要活动:

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //instantiates the parameters
        recyclerView = findViewById(R.id.recycler_view);
        
        adapter = new NBA_Adapter(getApplicationContext());
        layoutManager = new LinearLayoutManager(this);

        
        recyclerView.setAdapter(adapter);

        recyclerView.setLayoutManager(layoutManager);

    }

  
}

以下第一类的一部分:

 @Override
                public void onClick(View v) {
                    TEAMS current = (TEAMS) containerView.getTag();

                    
                    Intent intent = new Intent(v.getContext(), Second_Adapter.class);
                    intent.putExtra("id", current.getId());

                    v.getContext().startActivity(intent);
                }

我的第二堂课与我的第一堂课基本相同。我不使用同一回收者视图的唯一原因是我很难实现它,因为我还在每个回收者视图中使用搜索视图。因此,目前我正在分离它们。任何提示或链接都会受到赞赏,以表明我能做到这一点。

0 个答案:

没有答案