1. 程式人生 > 其它 >在微信介面中對recycleView的頁面進行點選跳轉設計-ZTY

在微信介面中對recycleView的頁面進行點選跳轉設計-ZTY

這次我們要實現給我們的微信介面中的recycleView進行點選跳轉到其他activity的操作

首先我們先建立3個新的activity,分別對應點選華為,蘋果,小米是跳轉的activity

然後在這三個activity對應的xml檔案中輸入詳細的引數,實現點選跳轉後會顯示詳細的資訊的功能

具體程式碼:

  1 <?xml version="1.0" encoding="utf-8"?>
  2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3     xmlns:app="http://schemas.android.com/apk/res-auto"
4 xmlns:tools="http://schemas.android.com/tools" 5 android:layout_width="match_parent" 6 android:layout_height="match_parent" 7 tools:context=".MainActivity4"> 8 9 <TextView 10 android:id="@+id/textView12" 11 android:layout_width="match_parent" 12
android:layout_height="match_parent" 13 android:layout_weight="1" 14 android:gravity="center" 15 android:text="華為手機具體引數:" 16 android:textSize="30sp" /> 17 18 <LinearLayout 19 android:layout_width="221dp" 20 android:layout_height
="match_parent" 21 android:orientation="vertical"> 22 23 <TextView 24 android:id="@+id/text_view5" 25 android:layout_width="match_parent" 26 android:layout_height="wrap_content" 27 android:layout_marginLeft="1dp" 28 android:layout_marginTop="1dp" 29 android:layout_marginRight="1dp" 30 android:layout_marginBottom="1dp" 31 android:layout_weight="1" 32 android:background="@android:color/holo_blue_dark" 33 android:gravity="center" 34 android:text="電池容量:4100mAh" 35 android:textColor="#4E342E" 36 android:textSize="30dp" /> 37 38 <TextView 39 android:id="@+id/text_view3" 40 android:layout_width="match_parent" 41 android:layout_height="wrap_content" 42 android:layout_marginLeft="1dp" 43 android:layout_marginTop="1dp" 44 android:layout_marginRight="1dp" 45 android:layout_marginBottom="1dp" 46 android:layout_weight="1" 47 android:background="@android:color/holo_blue_dark" 48 android:gravity="center" 49 android:text="螢幕尺寸:6.5英寸" 50 android:textColor="#4E342E" 51 android:textSize="30dp" /> 52 53 <TextView 54 android:id="@+id/text_view4" 55 android:layout_width="match_parent" 56 android:layout_height="wrap_content" 57 android:layout_marginLeft="1dp" 58 android:layout_marginTop="1dp" 59 android:layout_marginRight="1dp" 60 android:layout_marginBottom="1dp" 61 android:layout_weight="1" 62 android:background="@android:color/holo_blue_dark" 63 android:gravity="center" 64 android:text="螢幕色彩:10.7億色,P3廣色域" 65 android:textColor="#4E342E" 66 android:textSize="30dp" /> 67 68 <TextView 69 android:id="@+id/text_view9" 70 android:layout_width="match_parent" 71 android:layout_height="wrap_content" 72 android:layout_marginLeft="1dp" 73 android:layout_marginTop="1dp" 74 android:layout_marginRight="1dp" 75 android:layout_marginBottom="1dp" 76 android:layout_weight="1" 77 android:background="@android:color/holo_blue_dark" 78 android:gravity="center" 79 android:text="執行記憶體(RAM):8GB" 80 android:textColor="#4E342E" 81 android:textSize="30dp" /> 82 83 <TextView 84 android:id="@+id/text_view10" 85 android:layout_width="match_parent" 86 android:layout_height="wrap_content" 87 android:layout_marginLeft="1dp" 88 android:layout_marginTop="1dp" 89 android:layout_marginRight="1dp" 90 android:layout_marginBottom="1dp" 91 android:layout_weight="1" 92 android:background="@android:color/holo_blue_dark" 93 android:gravity="center" 94 android:text="機身記憶體(ROM):256GB" 95 android:textColor="#4E342E" 96 android:textSize="30dp" /> 97 98 <TextView 99 android:id="@+id/text_view11" 100 android:layout_width="match_parent" 101 android:layout_height="wrap_content" 102 android:layout_marginLeft="1dp" 103 android:layout_marginTop="1dp" 104 android:layout_marginRight="1dp" 105 android:layout_marginBottom="1dp" 106 android:layout_weight="1" 107 android:background="@android:color/holo_blue_dark" 108 android:gravity="center" 109 android:text="CPU型號:驍龍888 4G" 110 android:textColor="#4E342E" 111 android:textSize="30dp" /> 112 </LinearLayout> 113 </LinearLayout>

蘋果和小米的類似

然後我們需要在RecycleAdapterDome.java檔案的onBindViewHolder函式中,給holder.itemView新增監聽點選的操作,這樣我們就可以實現點選華為的任一區域即可跳轉到詳細資訊的功能。

為了判斷我們點選的是華為,蘋果還是小米,我們這裡需要引入一個判斷的邏輯

1 if(holder.textView1.getText() == "品牌:華為")

我這裡是用品牌的名字來進行判斷

然後我們為了跳轉到新的activity,需要建立一個Intent類的物件intent,Intent()的第一個引數是context,即在當前的activity中,第二個引數就是我們要跳轉的activity的名字,然後用startActivity()函式來啟動新的activity,並進行跳轉

 1 holder.itemView.setOnClickListener(new View.OnClickListener() {
 2             @Override
 3             public void onClick(View v) {
 4                 if(holder.textView1.getText() == "品牌:華為"){
 5                     Intent intent=new Intent(context,MainActivity4.class);
 6                     context.startActivity(intent);
 7                 }
 8                 if(holder.textView1.getText() == "品牌:蘋果"){
 9                     Intent intent=new Intent(context,MainActivity5.class);
10                     context.startActivity(intent);
11                 }
12                 if(holder.textView1.getText() == "品牌:小米"){
13                     Intent intent=new Intent(context,MainActivity6.class);
14                     context.startActivity(intent);
15                 }
16 
17             }
18         });

最後實現功能

點選華為區域之後跳轉到華為詳細的資訊

蘋果和小米類似

點選返回鍵可以返回到recycleView介面,實現功能