2021-10-24

在之前的基础上,对有recycleView的页面进行点击跳转设计。比如,某一tab页是新闻列表,则点击某一行能跳转到新闻详情页面;

整体思路:

主要思路为:先创建并注册好待调用的activity,然后在myadapter.java文件中对recyclerview的item创建监听。然后通过点击item的position跳转到相应的activity。

细节功能函数:

首先创建并在AndroidManifest里面注册activity:

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

    <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/Theme.2021_10_08">
        <activity
            android:name=".MainActivity3"
            android:exported="true"
            android:launchMode="singleInstance">
            <intent-filter>
                <action android:name="lyr.study.testActivity3" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>



        <activity
            android:name=".MainActivity2"
            android:exported="true"
            android:launchMode="singleInstance">
            <intent-filter>
                <action android:name="lyr.study.testActivity2" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

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

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

</manifest>

对item设置监听,然后利用switch语句,通过点击返回的position来进入不同的activity。


    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        holder.textView1.setText(data.get(position));

        itemView.setOnClickListener(view -> {
            switch (position){
                case 0:
                    Intent intent = new Intent("lyr.study.testActivity2");
                    view.getContext().startActivity(intent);
                    break;
                case 1:
                    intent = new Intent("lyr.study.testActivity3");
                    view.getContext().startActivity(intent);
                    break;
                default:
                    break;
            }


        });

效果展示:

运行之后的界面:
在这里插入图片描述
点击第一行,进入activity2:
在这里插入图片描述
点击第二行,进入activity3:
在这里插入图片描述

代码gitee地址

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值