移动开发作业2——RecycleView页面点击跳转设计

目录

一、项目总体介绍

二、关键步骤与核心技术

2.1 适配器myadapter的设计

2.2 被调Activity设计

三、结果展示

四、源码地址


一、项目总体介绍

1. 在前面所做的RecycleView基础上,对有RecycleView的页面进行点击跳转设计。本文设计从微信主页面点击跳转到与个人的聊天界面;

2. 本次作业考查的基础原理是对activity的生命周期的理解以及状态转变操作,并传递相关参数。

二、关键步骤与核心技术

2.1 适配器myadapter的设计

在myadapter.java文件中增加一个通过点击触发的监听,创建一个intent来实现从微信页面到被调MainAcitivity3页面的跳转,并且向MainAcitivity3发送数据(聊天对象的昵称)

@Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, @SuppressLint("RecyclerView") int position) {
        holder.textView1.setText(items.get(position).get("昵称").toString());
        holder.textView2.setText(items.get(position).get("时间").toString());
        holder.textView3.setText(items.get(position).get("聊天").toString());
        holder.imageView.setImageResource(Integer.parseInt(items.get(position).get("头像").toString()));
        holder.linearLayout5.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context,MainActivity3.class);
                intent.putExtra("name",items.get(position).get("昵称").toString());
                context.startActivity(intent);
            }
        });

    }

2.2 被调Activity设计

首先创建一个Activity组件

 添加回调方法

@Override
    protected void onPostResume() {
        super.onPostResume();
        lod.d("life","activity3 is onPostResume...");
    }

    @Override
    protected void onStart() {
        super.onStart();
        lod.d("life","activity3 is onStart...");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        lod.d("life","activity3 is onRestart...");
    }

    @Override
    protected void onStop() {
        super.onStop();
        lod.d("life","activity3 is onStop...");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        lod.d("life","activity3 is onDestroy...");
    }

    @Override
    public void finish(){
        super.finish();
        lod.d("life","activity3 is finish...");
    }

    @Override
    public void finishActivity(int requestCode){
        super.finishActivity(requestCode);
        lod.d("life","finishActivity3...");
    }

activity_main3界面设计

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity3">

    <TextView
        android:id="@+id/textView6"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:gravity="center"
        android:textSize="30dp"
        android:background="#D0D0D0"
        android:textColor="@color/black"
        android:text="昵称" />

    <TextView
                android:id="@+id/textView7"
                android:layout_width="503dp"
                android:layout_height="48dp"
                android:layout_gravity="center_vertical"
                android:gravity="center_vertical"
                android:layout_weight="1"
                android:background="@drawable/allaround_line"
                android:text="没有聊天记录"

                android:textSize="24dp" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/textView8"
            android:layout_width="326dp"
            android:layout_height="match_parent"
            android:background="@drawable/allaround_line"
            android:paddingLeft="15dp"
            android:paddingTop="15dp"
            android:paddingRight="10dp"
            android:paddingBottom="10dp"
            android:text="请输入内容"
            android:textSize="25dp" />

        <Button
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="#D0D0D0"
            android:text="发送"
            android:textColor="@color/white"
            android:textSize="24sp" />
    </LinearLayout>

</LinearLayout>

onCreate函数中通过intent接收到数据后,使用setText() 设置textView6的值,即昵称

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);
        lod.d("life","activity3 is onCreate...");
        Toast.makeText(this, "activity3 is onCreate...", Toast.LENGTH_SHORT).show();
        textView6=findViewById(R.id.textView6);
        Intent intent = getIntent();
        String name = intent.getStringExtra("name");
        textView6.setText(name);
    }

三、结果展示

   

四、源码地址

GitHub - zljdgit/MyApplication_work2

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值