提示 慎重复制
1 网络权限
2 导入依赖
compile 'com.android.support:recyclerview-v7:25.1.0' compile 'com.squareup.okhttp3:okhttp:3.4.1'
导gsonjar包
3代码
主页面布局
<?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" tools:context="com.example.zhangkai20180427.MainActivity" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:text="订单" android:layout_weight="9" android:layout_gravity="center" android:gravity="center" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/ic_launcher" android:layout_weight="1" android:id="@+id/btn" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="待支付" android:id="@+id/onefu" /> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="已支付" android:id="@+id/twofu" /> <Button android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="已取消" android:id="@+id/threefu" /> </LinearLayout> <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/fram" ></FrameLayout> </LinearLayout> item布局/<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/titledai" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/dai" android:layout_alignParentRight="true" /> </RelativeLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="价格 : " android:id="@+id/ll" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/pricedai" android:layout_toRightOf="@+id/ll" /> </RelativeLayout> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="20dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="创建时间:" android:id="@+id/yy" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@+id/yy" android:id="@+id/timedai" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="取消订单" android:layout_alignParentRight="true" android:id="@+id/btndai" /> </RelativeLayout> </LinearLayout>第一个fragment的布局///<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.RecyclerView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/recycle1" ></android.support.v7.widget.RecyclerView> </LinearLayout>第二个fragment的布局///<?xml version=