Android 列表分類
阿新 • • 發佈:2018-11-28
1.主頁面佈局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".fragment.LeftFragment" android:orientation="horizontal"> <android.support.v7.widget.RecyclerView android:id="@+id/mRecyclerView" android:layout_width="0dp" android:layout_weight="3" android:layout_height="match_parent"> </android.support.v7.widget.RecyclerView> <ScrollView android:id="@+id/mScrollView" android:layout_width="0dp" android:layout_weight="7" android:layout_height="match_parent"> <LinearLayout android:id="@+id/mLinearLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingLeft="15dp"></LinearLayout> </ScrollView> </LinearLayout>
2.左邊頁面的佈局
<?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"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/title" android:text="666666" android:textSize="20sp" android:padding="15dp"/> </LinearLayout>
3.右邊頁面的佈局
<?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:orientation="vertical"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/image" android:src="@drawable/ic_launcher_background" android:layout_gravity="center_horizontal"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/name" android:text="6666" android:textColor="#000" android:layout_marginTop="5dp" android:layout_gravity="center_horizontal"/> </LinearLayout>
4.UtilsModel工具類M層(get.post兩種)
package com.bawie.www.month1.model;
import android.os.Handler;
import android.os.Looper;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
/**
* date:2018/11/22
* author:別來無恙(別來無恙)
* function:
*/
public class UtilsModel {
private final Handler mHandler;
public static UtilsModel sUtilsModel;
private final OkHttpClient mMOkHttpClient;
private UtilsModel(){
mHandler = new Handler(Looper.getMainLooper());
InterceptorModel interceptorModel = new InterceptorModel();
mMOkHttpClient = new OkHttpClient.Builder()
.addInterceptor(interceptorModel)
.readTimeout(3000, TimeUnit.MILLISECONDS)
.writeTimeout(3000, TimeUnit.MILLISECONDS)
.readTimeout(3000, TimeUnit.MILLISECONDS)
.build();
}
public static UtilsModel getInstance(){
if (sUtilsModel == null){
synchronized (UtilsModel.class){
if (sUtilsModel == null){
return sUtilsModel = new UtilsModel();
}
}
}
return sUtilsModel;
}
public interface ModelInterface{
void success(String data);
void failed();
}
public void doGet(String url, final ModelInterface modelInterface){
Request request = new Request.Builder()
.get()
.url(url)
.build();
Call call = mMOkHttpClient.newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
mHandler.post(new Runnable() {
@Override
public void run() {
modelInterface.failed();
}
});
}
@Override
public void onResponse(Call call, Response response) throws IOException {
final String data = response.body().string();
mHandler.post(new Runnable() {
@Override
public void run() {
modelInterface.success(data);
}
});
}
});
}
public void doPost(String url, Map<String,String> map,final ModelInterface modelInterface){
FormBody.Builder builder = new FormBody.Builder();
for (String key:map.keySet()){
builder.add(key,map.get(key));
}
FormBody formBody = builder.build();
Request request = new Request.Builder()
.post(formBody)
.url(url)
.build();
Call call = mMOkHttpClient.newCall(request);
call.enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
modelInterface.failed();
}
@Override
public void onResponse(Call call, Response response) throws IOException {
final String data = response.body().string();
mHandler.post(new Runnable() {
@Override
public void run() {
modelInterface.success(data);
}
});
}
});
}
}
5.左邊presenter(get)
package com.bawie.www.month1.presenter;
import com.bawie.www.month1.HttpView;
import com.bawie.www.month1.bean.LeftBean;
import com.bawie.www.month1.model.UtilsModel;
import com.google.gson.Gson;
import java.util.List;
/**
* date:2018/11/22
* author:別來無恙(別來無恙)
* function:
*/
public class RecyPresenter {
public void mkkPresenter(String url, final PresenterInterface presenterInterface){
UtilsModel instance = UtilsModel.getInstance();
instance.doGet(url, new UtilsModel.ModelInterface() {
@Override
public void success(String data) {
LeftBean leftBean = new Gson().fromJson(data, LeftBean.class);
List<LeftBean.DataBean> data1 = leftBean.getData();
presenterInterface.success(data1);
}
@Override
public void failed() {
presenterInterface.failed();
}
});
}
public interface PresenterInterface{
void success(List<LeftBean.DataBean> data1);
void failed();
}
}
6.右邊presenter(post)
package com.bawie.www.month1.presenter;
import com.bawie.www.month1.bean.RightBean;
import com.bawie.www.month1.model.UtilsModel;
import com.google.gson.Gson;
import java.util.List;
import java.util.Map;
/**
* date:2018/11/22
* author:別來無恙(別來無恙)
* function:
*/
public class RightPresenter {
public void RightPresenter(String url, Map<String,String> map, final RightInterface rightInterface){
UtilsModel instance = UtilsModel.getInstance();
instance.doPost(url, map, new UtilsModel.ModelInterface() {
@Override
public void success(String data) {
RightBean rightBean = new Gson().fromJson(data, RightBean.class);
List<RightBean.DataBean> data1 = rightBean.getData();
rightInterface.success(data1);
}
@Override
public void failed() {
rightInterface.failed();
}
});
}
public interface RightInterface{
void success(List<RightBean.DataBean> data1);
void failed();
}
}
7.左邊adapter
package com.bawie.www.month1.adapter;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.bawie.www.month1.R;
import com.bawie.www.month1.bean.LeftBean;
import java.util.List;
/**
* date:2018/11/22
* author:別來無恙(別來無恙)
* function:
*/
public class RecyAdapter extends RecyclerView.Adapter<RecyAdapter.ViewHoldere> {
private List<LeftBean.DataBean> left;
private Context mContext;
public RecyAdapter(List<LeftBean.DataBean> left, Context context) {
this.left = left;
mContext = context;
}
@NonNull
@Override
public ViewHoldere onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view = View.inflate(mContext, R.layout.item_left,null);
ViewHoldere viewHoldere = new ViewHoldere(view);
return viewHoldere;
}
@Override
public void onBindViewHolder(@NonNull ViewHoldere viewHoldere, final int i) {
viewHoldere.mTitle.setText(left.get(i).getName());
viewHoldere.mTitle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mRecyAdapterInterface.success(left.get(i).getCid() + "");
}
});
}
@Override
public int getItemCount() {
return left.size();
}
public class ViewHoldere extends RecyclerView.ViewHolder {
private final TextView mTitle;
public ViewHoldere(@NonNull View itemView) {
super(itemView);
mTitle = itemView.findViewById(R.id.title);
}
}
//點選條目的介面回撥
public interface RecyAdapterInterface{
void success(String s);
}
private RecyAdapterInterface mRecyAdapterInterface;
public void setRecyAdapterInterface(RecyAdapterInterface recyAdapterInterface){
mRecyAdapterInterface = recyAdapterInterface;
}
}
8.右邊的adapter
package com.bawie.www.month1.adapter;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.bawie.www.month1.R;
import com.bawie.www.month1.bean.RightBean;
import com.squareup.picasso.Picasso;
import java.util.List;
/**
* date:2018/11/22
* author:別來無恙(別來無恙)
* function:
*/
public class RightAdapter extends RecyclerView.Adapter<RightAdapter.ViewHolder> {
private Context mContext;
private List<RightBean.DataBean> right;
public RightAdapter(Context context, List<RightBean.DataBean> right) {
mContext = context;
this.right = right;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view = View.inflate(mContext, R.layout.item_right,null);
ViewHolder viewHolder = new ViewHolder(view);
return viewHolder;
}
@Override
public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
RightBean.DataBean dataBean = right.get(i);
Picasso.with(mContext).load(dataBean.getList().get(i).getIcon()).into(viewHolder.mImage);
viewHolder.mName.setText(dataBean.getList().get(i).getName());
}
@Override
public int getItemCount() {
return right.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
private final ImageView mImage;
private final TextView mName;
public ViewHolder(@NonNull View itemView) {
super(itemView);
mImage = itemView.findViewById(R.id.image);
mName = itemView.findViewById(R.id.name);
}
}
}
9.主頁面
package com.bawie.www.month1.fragment;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import com.bawie.www.month1.HttpView;
import com.bawie.www.month1.R;
import com.bawie.www.month1.adapter.RecyAdapter;
import com.bawie.www.month1.adapter.RightAdapter;
import com.bawie.www.month1.bean.LeftBean;
import com.bawie.www.month1.bean.RightBean;
import com.bawie.www.month1.presenter.RecyPresenter;
import com.bawie.www.month1.presenter.RightPresenter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* A simple {@link Fragment} subclass.
*/
public class LeftFragment extends Fragment {
//左側
public static final String LeftUrl = "http://www.zhaoapi.cn/product/getCatagory";
public static final String RightUrl = "http://www.zhaoapi.cn/product/getProductCatagory";
private RecyclerView mRecyclerView;
private LinearLayout mLinearLayout;
private ScrollView mScrollView;
private String CID;
public LeftFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = View.inflate(getActivity(), R.layout.fragment_left, null);
//初始化控制元件
initView(view);
//初始化資料
initData();
return view;
}
/**
* 初始化資料
*/
private void initData() {
//加一個條目分割線 垂直
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL);
//新增到mRecyclerView裡邊
mRecyclerView.addItemDecoration(dividerItemDecoration);
//設定LinearLayoutManager
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
//建立P層
RecyPresenter recyPresenter = new RecyPresenter();
recyPresenter.mkkPresenter(LeftUrl, new RecyPresenter.PresenterInterface() {
@Override
public void success(List<LeftBean.DataBean> data1) {
//recyadapter
RecyAdapter recyAdapter = new RecyAdapter(data1, getActivity());
mRecyclerView.setAdapter(recyAdapter);
recyAdapter.setRecyAdapterInterface(new RecyAdapter.RecyAdapterInterface() {
@Override
public void success(String s) {
//先在上邊定義一個CID
Toast.makeText(getActivity(), s, Toast.LENGTH_SHORT).show();
CID = s;
initRight();
}
});
}
@Override
public void failed() { }
});
}
private void initRight() {
RightPresenter rightPresenter = new RightPresenter();
final Map<String,String> map = new HashMap<>();
map.put("cid",CID);
rightPresenter.RightPresenter(RightUrl, map, new RightPresenter.RightInterface() {
@Override
public void success(List<RightBean.DataBean> data1) {
mLinearLayout.removeAllViews();
if (data1 != null){
for (int i = 0; i < data1.size(); i++) {
TextView textView = new TextView(getContext());
textView.setTextSize(20);
textView.setTextColor(Color.RED);
textView.setText(data1.get(i).getName());
//建立網格佈局
GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(), 4);
//建立RecyclerView
RecyclerView recyclerView = new RecyclerView(getContext());
//新增到佈局管理器
recyclerView.setLayoutManager(gridLayoutManager);
//建立介面卡
RightAdapter rightAdapter = new RightAdapter(getContext(), data1);
//新增介面卡
recyclerView.setAdapter(rightAdapter);
//更新介面卡
rightAdapter.notifyDataSetChanged();
mLinearLayout.addView(textView);
mLinearLayout.addView(recyclerView);
}
}
}
@Override
public void failed() {
}
});
}
/**
* 初始化控制元件
* @param view
*/
private void initView(View view) {
mRecyclerView = (RecyclerView) view.findViewById(R.id.mRecyclerView);
mLinearLayout = (LinearLayout) view.findViewById(R.id.mLinearLayout);
mScrollView = (ScrollView) view.findViewById(R.id.mScrollView);
}
}
10.左邊bean
package com.bawie.www.month1.bean;
import java.util.List;
/**
* date:2018/11/22
* author:別來無恙(別來無恙)
* function:
*/
public class LeftBean {
/**
* msg :
* code : 0
* data : [{"cid":1,"createtime":"2017-10-10T19:41:39","icon":"http://120.27.23.105/images/category/shop.png","ishome":1,"name":"京東超市"},{"cid":2,"createtime":"2017-10-10T19:41:39","icon":"http://120.27.23.105/images/category/qqg.png","ishome":1,"name":"全球購"},{"cid":3,"createtime":"2017-10-10T19:45:11","icon":"http://120.27.23.105/images/category/phone.png","ishome":1,"name":"手機數碼"},{"cid":5,"createtime":"2017-10-10T20:12:03","icon":"http://120.27.23.105/images/category/man.png","ishome":1,"name":"男裝"},{"cid":6,"createtime":"2017-10-10T20:12:03","icon":"http://120.27.23.105/images/category/girl.png","ishome":1,"name":"女裝"},{"cid":7,"createtime":"2017-10-10T20:12:03","icon":"http://120.27.23.105/images/category/manshoe.png","ishome":1,"name":"男鞋"},{"cid":8,"createtime":"2017-10-10T20:12:03","icon":"http://120.27.23.105/images/category/girlshoe.png","ishome":1,"name":"女鞋"},{"cid":9,"createtime":"2017-10-10T20:12:03","icon":"http://120.27.23.105/images/category/shirt.png","ishome":1,"name":"內衣配飾"},{"cid":10,"createtime":"2017-10-10T20:12:03","icon":"http://120.27.23.105/images/category/bag.png","ishome":1,"name":"箱包手袋"},{"cid":11,"createtime":"2017-10-10T20:12:03","icon":"http://120.27.23.105/images/category/beauty.png","ishome":1,"name":"美妝個護"},{"cid":12,"createtime":"2017-10-10T20:12:03","icon":"http://120.27.23.105/images/category/jewel.png","ishome":1,"name":"鐘錶珠寶"},{"cid":13,"createtime":"2017-10-10T20:12:03","icon":"http://120.27.23.105/images/category/luxury.png","ishome":1,"name":"奢侈品"},{"cid":14,"createtime":"2017-10-10T20:12:03","icon":"http://120.27.23.105/images/category/computer.png","ishome":1,"name":"電腦辦公"},{"cid":15,"createtime":"2017-09-29T10:13:48","icon":"http://120.27.23.105/images/icon.png","ishome":0,"name":"家用電器"},{"cid":16,"createtime":"2017-09-29T10:13:48","icon":"http://120.27.23.105/images/icon.png","ishome":0,"name":"食品生鮮"},{"cid":17,"createtime":"2017-09-29T10:13:48","icon":"http://120.27.23.105/images/icon.png","ishome":0,"name":"酒水飲料"},{"cid":18,"createtime":"2017-09-29T10:13:48","icon":"http://120.27.23.105/images/icon.png","ishome":0,"name":"母嬰童裝"},{"cid":19,"createtime":"2017-09-29T10:13:48","icon":"http://120.27.23.105/images/icon.png","ishome":0,"name":"玩具樂器"},{"cid":20,"createtime":"2017-09-29T10:13:48","icon":"http://120.27.23.105/images/icon.png","ishome":0,"name":"醫藥保健"}]
*/
private String msg;
private String code;
private List<DataBean> data;
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public List<DataBean> getData() {
return data;
}
public void setData(List<DataBean> data) {
this.data = data;
}
public static class DataBean {
/**
* cid : 1
* createtime : 2017-10-10T19:41:39
* icon : http://120.27.23.105/images/category/shop.png
* ishome : 1
* name : 京東超市
*/
private int cid;
private String createtime;
private String icon;
private int ishome;
private String name;
public int getCid() {
return cid;
}
public void setCid(int cid) {
this.cid = cid;
}
public String getCreatetime() {
return createtime;
}
public void setCreatetime(String createtime) {
this.createtime = createtime;
}
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public int getIshome() {
return ishome;
}
public void setIshome(int ishome) {
this.ishome = ishome;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
11.右邊bean
package com.bawie.www.month1.bean;
import java.util.List;
/**
* date:2018/11/22
* author:別來無恙(別來無恙)
* function:
*/
public class RightBean {
/**
* msg : 獲取子分類成功
* code : 0
* data : [{"cid":"1","list":[{"icon":"http://120.27.23.105/images/icon.png","name":"月餅","pcid":1,"pscid":1},{"icon":"http://120.27.23.105/images/icon.png","name":"堅果炒貨","pcid":1,"pscid":2},{"icon":"http://120.27.23.105/images/icon.png","name":"糖巧","pcid":1,"pscid":3},{"icon":"http://120.27.23.105/images/icon.png","name":"休閒零食","pcid":1,"pscid":4},{"icon":"http://120.27.23.105/images/icon.png","name":"肉乾肉脯","pcid":1,"pscid":5},{"icon":"http://120.27.23.105/images/icon.png","name":"餅乾蛋糕","pcid":1,"pscid":6},{"icon":"http://120.27.23.105/images/icon.png","name":"蜜餞果乾","pcid":1,"pscid":7},{"icon":"http://120.27.23.105/images/icon.png","name":"無糖食品","pcid":1,"pscid":8}],"name":"休閒零食","pcid":"1"},{"cid":"1","list":[{"icon":"http://120.27.23.105/images/icon.png","name":"新鮮水果","pcid":2,"pscid":9},{"icon":"http://120.27.23.105/images/icon.png","name":"海鮮水產","pcid":2,"pscid":10},{"icon":"http://120.27.23.105/images/icon.png","name":"精選肉類","pcid":2,"pscid":11},{"icon":"http://120.27.23.105/images/icon.png","name":"蛋類","pcid":2,"pscid":12},{"icon":"http://120.27.23.105/images/icon.png","name":"新鮮蔬菜","pcid":2,"pscid":13},{"icon":"http://120.27.23.105/images/icon.png","name":"冷凍食品","pcid":2,"pscid":14},{"icon":"http://120.27.23.105/images/icon.png","name":"飲品甜品","pcid":2,"pscid":15},{"icon":"http://120.27.23.105/images/icon.png","name":"大閘蟹","pcid":2,"pscid":16}],"name":"京東生鮮","pcid":"2"},{"cid":"1","list":[{"icon":"http://120.27.23.105/images/icon.png","name":"大米","pcid":3,"pscid":21},{"icon":"http://120.27.23.105/images/icon.png","name":"麵粉","pcid":3,"pscid":22},{"icon":"http://120.27.23.105/images/icon.png","name":"雜糧","pcid":3,"pscid":23},{"icon":"http://120.27.23.105/images/icon.png","name":"食用油","pcid":3,"pscid":24},{"icon":"http://120.27.23.105/images/icon.png","name":"調味品","pcid":3,"pscid":25},{"icon":"http://120.27.23.105/images/icon.png","name":"方便速食","pcid":3,"pscid":26},{"icon":"http://120.27.23.105/images/icon.png","name":"有機食品","pcid":3,"pscid":27}],"name":"糧油調味","pcid":"3"},{"cid":"1","list":[{"icon":"http://120.27.23.105/images/icon.png","name":"飲用水","pcid":4,"pscid":28},{"icon":"http://120.27.23.105/images/icon.png","name":"飲料","pcid":4,"pscid":29},{"icon":"http://120.27.23.105/images/icon.png","name":"牛奶乳品","pcid":4,"pscid":30},{"icon":"http://120.27.23.105/images/icon.png","name":"名茶","pcid":4,"pscid":31},{"icon":"http://120.27.23.105/images/icon.png","name":"蜂蜜","pcid":4,"pscid":32}],"name":"水飲茗茶","pcid":"4"},{"cid":"1","list":[{"icon":"http://120.27.23.105/images/icon.png","name":"白酒","pcid":5,"pscid":33},{"icon":"http://120.27.23.105/images/icon.png","name":"葡萄酒","pcid":5,"pscid":34},{"icon":"http://120.27.23.105/images/icon.png","name":"洋酒","pcid":5,"pscid":35},{"icon":"http://120.27.23.105/images/icon.png","name":"啤酒","pcid":5,"pscid":36},{"icon":"http://120.27.23.105/images/icon.png","name":"黃酒","pcid":5,"pscid":37},{"icon":"http://120.27.23.105/images/icon.png","name":"陳年老酒","pcid":5,"pscid":38}],"name":"中外名酒","pcid":"5"}]
*/
private String msg;
private String code;
private List<DataBean> data;
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public List<DataBean> getData() {
return data;
}
public void setData(List<DataBean> data) {
this.data = data;
}
public static class DataBean {
/**
* cid : 1
* list : [{"icon":"http://120.27.23.105/images/icon.png","name":"月餅","pcid":1,"pscid":1},{"icon":"http://120.27.23.105/images/icon.png","name":"堅果炒貨","pcid":1,"pscid":2},{"icon":"http://120.27.23.105/images/icon.png","name":"糖巧","pcid":1,"pscid":3},{"icon":"http://120.27.23.105/images/icon.png","name":"休閒零食","pcid":1,"pscid":4},{"icon":"http://120.27.23.105/images/icon.png","name":"肉乾肉脯","pcid":1,"pscid":5},{"icon":"http://120.27.23.105/images/icon.png","name":"餅乾蛋糕","pcid":1,"pscid":6},{"icon":"http://120.27.23.105/images/icon.png","name":"蜜餞果乾","pcid":1,"pscid":7},{"icon":"http://120.27.23.105/images/icon.png","name":"無糖食品","pcid":1,"pscid":8}]
* name : 休閒零食
* pcid : 1
*/
private String cid;
private String name;
private String pcid;
private List<ListBean> list;
public String getCid() {
return cid;
}
public void setCid(String cid) {
this.cid = cid;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPcid() {
return pcid;
}
public void setPcid(String pcid) {
this.pcid = pcid;
}
public List<ListBean> getList() {
return list;
}
public void setList(List<ListBean> list) {
this.list = list;
}
public static class ListBean {
/**
* icon : http://120.27.23.105/images/icon.png
* name : 月餅
* pcid : 1
* pscid : 1
*/
private String icon;
private String name;
private int pcid;
private int pscid;
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPcid() {
return pcid;
}
public void setPcid(int pcid) {
this.pcid = pcid;
}
public int getPscid() {
return pscid;
}
public void setPscid(int pscid) {
this.pscid = pscid;
}
}
}
}
注意:
//okhttp依賴
implementation 'com.squareup.okhttp3:okhttp:3.12.0'
//recyclerView依賴
implementation 'com.android.support:recyclerview-v7:28.0.0'
//gson依賴
implementation 'com.google.code.gson:gson:2.2.4'
//picasso依賴
implementation 'com.squareup.picasso:picasso:2.3.2'
//網路許可權
<uses-permission android:name="android.permission.INTERNET"/>
//左邊網路請求地址
public static final String LeftUrl = "http://www.zhaoapi.cn/product/getCatagory";
//右邊網路請求地址
public static final String RightUrl = "http://www.zhaoapi.cn/product/getProductCatagory";