相关视频教程在某站上面(🔍浩宇软件开发)
1. 涉及到的技术点
- Intent启动意图,Activity页面之间的跳转
- intent.putExtra(‘xxxx’),Activity之间传值
- RelativeLayout相对布局的使用
2.代码实现过程
- 在上集中,已经实现了商品分类+商品分类列表,在HomeFragment.java中,添加列表点击事件
//recyclerView点击事件
mRightListAdapter.setOnItemClickListener(new RightListAdapter.onItemClickListener() {
@Override
public void onItemClick(ProductInfo productInfo, int position) {
//跳转传值
Intent intent =new Intent(getActivity(), ProductDetailsActivity.class);
//intent 传递对象的时候,实体类一定要 implements Serializable
intent.putExtra("productInfo",productInfo);
startActivity(intent);
}
});
在上面的代码中,intent.putExtra()传递的是一个对象,在传递对象的时候,相对应的实体一定要实现 Serializable
- 商品详情activity_product_details.xml布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
tools:context=".ProductDetailsActivity">
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/my_light_primary"
app:navigationIcon="@drawable/baseline_arrow_back_24"
app:title="详情"
app:titleTextColor="@color/white" />
<ImageView
android:id=