京东分类
compile 'com.github.bumptech.glide:glide:3.7.0' compile 'com.jcodecraeer:xrecyclerview:1.5.9'
api 'com.squareup.okhttp3:okhttp:3.9.1' compile 'com.squareup.okhttp3:logging-interceptor:3.4.1' compile 'com.google.code.gson:gson:2.8.2'activity_main.xml
<?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" android:orientation="horizontal" android:background="#eee" tools:context="com.example.monthpractice1.view.MainActivity"> <android.support.v7.widget.RecyclerView android:id="@+id/left_list" android:layout_width="100dp" android:layout_height="match_parent"></android.support.v7.widget.RecyclerView> <android.support.v7.widget.RecyclerView android:id="@+id/right_list" android:layout_marginLeft="20dp" android:layout_width="match_parent" android:layout_height="match_parent"></android.support.v7.widget.RecyclerView> </LinearLayout>group_item.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/item_title" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="10dp"/> <android.support.v7.widget.RecyclerView android:id="@+id/item_list" android:background="#fff" android:layout_width="match_parent" android:layout_height="wrap_content"></android.support.v7.widget.RecyclerView> </LinearLayout>item.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="match_parent" android:gravity="center_horizontal" android:orientation="vertical" android:padding="10dp"> <ImageView android:id="@+id/myimg" android:layout_width="match_parent" android:layout_height="60dp" /> <TextView android:id="@+id/mytitle" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" /> </LinearLayout>
text_item.xml
<?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:background="#fff" android:orientation="vertical" > <TextView android:id="@+id/left_title" android:padding="20dp" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout>
view
MainActivity.java
package com.example.monthpractice1.view; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.View; import android.widget.Toast; import com.example.monthpractice1.R; import com.example.monthpractice1.adapter.GroupAdapter; import com.example.monthpractice1.adapter.LeftAdapter; import com.example.monthpractice1.adapter.OnItemClickListner; import com.example.monthpractice1.bean.CatagoryBean; import com.example.monthpractice1.bean.GroupGoodsBean; import com.example.monthpractice1.contract.IShowCardView; import com.example.monthpractice1.presenter.ShowGoodsPresenter; import java.util.List; public class MainActivity extends AppCompatActivity implements IShowCardView { private RecyclerView leftList, rightList; private LeftAdapter adapter; private GroupAdapter groupAdapter; private ShowGoodsPresenter presenter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); leftList = (RecyclerView) findViewById(R.id.left_list); rightList = (RecyclerView) findViewById(R.id.right_list); leftList.setLayoutManager(new LinearLayoutManager(MainActivity.this)); rightList.setLayoutManager(new LinearLayoutManager(MainActivity.this)); groupAdapter = new GroupAdapter(MainActivity.this); rightList.setAdapter(groupAdapter); presenter = new ShowGoodsPresenter(); presenter.attachView(this); presenter.getGoodsList(); } @Override public void showRightData(List<GroupGoodsBean.DataBean> data) { groupAdapter.updateData(data); } @Override public void showCardData(List<CatagoryBean.DataBean> data) { LeftAdapter adapter = new LeftAdapter(MainActivity.this, data); leftList.setAdapter(adapter); adapter.setClick(new OnItemClickListner() { @Override public void onItemClick(View view, int cid) { presenter.showRightList(cid); } }); } @Override public void showError(String error) { Toast.makeText(MainActivity.this, error, Toast.LENGTH_SHORT).show(); } @Override protected void onDestroy() { super.onDestroy(); presenter.detachView(this); } }
utils
GsonObjectCallback.java
package com.example.monthpractice1.utils; import android.os.Handler; import com.google.gson.Gson; import java.io.IOException; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import okhttp3.Call; import okhttp3.Callback; import okhttp3.Response; /** * 1. 类的用途 如果要将得到的json直接转化为集合 建议使用该类 * 该类的onUi() onFailed()方法运行在主线程 * 2. @author forever * 3. @date 2017/9/24 18:47 */ public abstract class GsonObjectCallback<T> implements Callback { private Handler handler = new Handler(); //主线程处理 public abstract void onUi(T t); //主线程处理 public abstract void onFailed(Call call, IOException e); //请求失败 @Override public void onFailure(final Call call, final IOException e) { handler.post(new Runnable() { @Override public void run() { onFailed(call, e); } }); } //请求json 并直接返回泛型的对象 主线程处理 @Override public void onResponse(Call call, Response response) throws IOException { String json = response.body().string(); Class<T> cls = null; Class clz = this.getClass(); ParameterizedType type = (ParameterizedType) clz.getGenericSuperclass(); Type[] types = type.getActualTypeArguments(); cls = (Class<T>) types[0]; Gson gson = new Gson(); final T t = gson.fromJson(json, cls); handler.post(new Runnable() { @Override public void run() { onUi(t); } }); } }
OkhttpUtil.java
package com.example.monthpractice1.utils; import android.os.Environment; import java.io.File; import java.util.Map; import java.util.concurrent.TimeUnit; import okhttp3.Cache; import okhttp3.Call; import okhttp3.Callback; import okhttp3.FormBody; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.internal.cache.CacheInterceptor; import okhttp3.logging.HttpLoggingInterceptor; /** * Created by mamiaomiao on 2018/2/27. */ public class OkhttpUtil { private static OkhttpUtil util; private OkhttpUtil() { } public OkhttpUtil getInstance() { if (util == null) { synchronized (OkhttpUtil.class) { if (util == null) { util = new OkhttpUtil(); } } } return util; } private static OkHttpClient okHttpClient; private static OkHttpClient getOkHttpClient(){ if(okHttpClient==null){ File sdcache = new File(Environment.getExternalStorageDirectory(), "cache"); int cacheSize = 10 * 1024 * 1024; okHttpClient=new OkHttpClient.Builder() .connectTimeout(15, TimeUnit.SECONDS) .cache(new Cache(sdcache,cacheSize)) .build(); } return okHttpClient; } /** * get请求 * 参数1 url * 参数2 回调Callback */ public static void doGet(String url, Callback callback) { //创建OkHttpClient请求对象 OkHttpClient okHttpClient = getOkHttpClient(); //创建Request Request request = new Request.Builder().url(url).build(); //得到Call对象 Call call = okHttpClient.newCall(request); //执行异步请求 call.enqueue(callback); } /** * post请求 * 参数1 url * 参数2 回调Callback */ public static void doPost(String url, Map<String, String> params, Callback callback) { //创建OkHttpClient请求对象 OkHttpClient okHttpClient = getOkHttpClient(); //3.x版本post请求换成FormBody 封装键值对参数 FormBody.Builder builder = new FormBody.Builder(); //遍历集合 for (String key : params.keySet()) { builder.add(key, params.get(key)); } //创建Request Request request = new Request.Builder().url(url).post(builder.build()).build(); Call call = okHttpClient.newCall(request); call.enqueue(callback); } }
presenter
ShowGoodsPresenter.java
package com.example.monthpractice1.presenter; import com.example.monthpractice1.bean.CatagoryBean; import com.example.monthpractice1.bean.GroupGoodsBean; import com.example.monthpractice1.contract.IShowCardView; import com.example.monthpractice1.model.ShowCardModel; import com.example.monthpractice1.utils.GsonObjectCallback; import java.io.IOException; import java.lang.ref.WeakReference; import java.util.List; import okhttp3.Call; /** * Created by mamiaomiao on 2018/2/27. */ public class ShowGoodsPresenter { private WeakReference<IShowCardView> reference; private ShowCardModel model; public ShowGoodsPresenter() { model = new ShowCardModel(); } public void attachView(IShowCardView view) { reference = new WeakReference<IShowCardView>(view); } public void detachView(IShowCardView view) { if (reference != null) { reference.clear(); reference = null; } } public void getGoodsList() { //获取图一左侧分类列表 model.getGoodsCard("https://www.zhaoapi.cn/product/getCatagory", new GsonObjectCallback<CatagoryBean>() { @Override public void onUi(CatagoryBean o) { //图一左侧分类列表加载完成以后,右侧默认显示第一个分类对应的商品子分类列表 if (o != null && o.getData() != null) { List<CatagoryBean.DataBean> bean = o.getData(); if (bean != null) { reference.get().showCardData(bean); if (bean.size() > 0) { getRightData(bean.get(0).getCid()); } } else { reference.get().showError("数据为空"); } } } @Override public void onFailed(Call call, IOException e) { reference.get().showError(e.getMessage()); } }); } //获取图一右侧列表数据 public void showRightList(int cid){ getRightData(cid); } private void getRightData(int cid){ model.getRightData("https://www.zhaoapi.cn/product/getProductCatagory?cid=" + cid, new GsonObjectCallback<GroupGoodsBean>() { @Override public void onUi(GroupGoodsBean groupGoodsBean) { if (groupGoodsBean != null && groupGoodsBean.getData() != null) { reference.get().showRightData(groupGoodsBean.getData()); } } @Override public void onFailed(Call call, IOException e) { } }); } }
model
ShowCardModel.java
package com.example.monthpractice1.model; import com.example.monthpractice1.bean.CatagoryBean; import com.example.monthpractice1.bean.GroupGoodsBean; import com.example.monthpractice1.contract.IShowCardModel; import com.example.monthpractice1.utils.GsonObjectCallback; import com.example.monthpractice1.utils.OkhttpUtil; import java.io.IOException; import okhttp3.Call; import okhttp3.Callback; import okhttp3.Response; /** * Created by mamiaomiao on 2018/2/27. */ public class ShowCardModel implements IShowCardModel { @Override public void getGoodsCard(String url,GsonObjectCallback callback) { OkhttpUtil.doGet(url, callback); } @Override public void getRightData(String url, GsonObjectCallback<GroupGoodsBean> callback) { OkhttpUtil.doGet(url,callback); } }
contract
IShowCardModel.java
package com.example.monthpractice1.contract; import com.example.monthpractice1.bean.CatagoryBean; import com.example.monthpractice1.bean.GroupGoodsBean; import com.example.monthpractice1.utils.GsonObjectCallback; /** * Created by mamiaomiao on 2018/2/27. */ public interface IShowCardModel { void getRightData(String url, GsonObjectCallback<GroupGoodsBean> callback); void getGoodsCard(String url, GsonObjectCallback<CatagoryBean> callback); }
IShowCardView.java
package com.example.monthpractice1.contract; import com.example.monthpractice1.bean.CatagoryBean; import com.example.monthpractice1.bean.GroupGoodsBean; import java.util.List; /** * Created by mamiaomiao on 2018/2/27. */ public interface IShowCardView { void showRightData(List<GroupGoodsBean.DataBean> data); void showCardData(List<CatagoryBean.DataBean> data); void showError(String error); }
bean
CatagoryBean.java
package com.example.monthpractice1.bean; import java.util.List; /** * Created by mamiaomiao on 2018/2/27. * 1. 商品分类接口 https://www.zhaoapi.cn/product/getCatagory */ public class CatagoryBean { /** * 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; } } }
package com.example.monthpractice1.bean; import java.util.List; /** * Created by mamiaomiao on 2018/2/27. * 1. 商品分类接口 https://www.zhaoapi.cn/product/getCatagory */ public class CatagoryBean { /** * 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; } } }
GroupGoodsBean.java
package com.example.monthpractice1.bean; import java.util.List; /** * Created by mamiaomiao on 2018/2/27. * https://www.zhaoapi.cn/product/getProductCatagory 请求参数: cid 商品分类id string字符串 必传 */ public class GroupGoodsBean { /** * 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; } } } }
adapter
GroupAdapter.java
package com.example.monthpractice1.adapter; import android.content.Context; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import com.example.monthpractice1.R; import com.example.monthpractice1.bean.GroupGoodsBean; import java.util.ArrayList; import java.util.List; /** * Created by mamiaomiao on 2018/2/27. * 图一右侧嵌套recyclerview的适配器 */ public class GroupAdapter extends RecyclerView.Adapter<GroupAdapter.GroupViewHolder> { private List<GroupGoodsBean.DataBean> list = new ArrayList<>(); private Context context; public GroupAdapter(Context context ) { this.context = context; } //刷新数据 public void updateData(List<GroupGoodsBean.DataBean> list){ this.list.clear(); this.list.addAll(list); notifyDataSetChanged(); } @Override public GroupViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(context).inflate(R.layout.group_item, null); return new GroupViewHolder(view); } @Override public void onBindViewHolder(GroupViewHolder holder, int position) { holder.textView.setText(list.get(position).getName()); holder.recyclerView.setLayoutManager(new GridLayoutManager(context, 3)); MyAdapter adapter = new MyAdapter(context); //为图一嵌套的recyclerview设置适配器 holder.recyclerView.setAdapter(adapter); adapter.addData(list.get(position).getList()); } @Override public int getItemCount() { return list.size(); } class GroupViewHolder extends RecyclerView.ViewHolder { public TextView textView; public RecyclerView recyclerView; public GroupViewHolder(View itemView) { super(itemView); textView = (TextView) itemView.findViewById(R.id.item_title); recyclerView = (RecyclerView) itemView.findViewById(R.id.item_list); } } }
LeftAdapter.java
package com.example.monthpractice1.adapter; import android.content.Context; import android.graphics.Color; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import com.example.monthpractice1.R; import com.example.monthpractice1.bean.CatagoryBean; import java.util.ArrayList; import java.util.List; /** * Created by mamiaomiao on 2018/2/27. * 图一左侧商品分类列表的适配器 */ public class LeftAdapter extends RecyclerView.Adapter<LeftAdapter.LeftViewHolder> { private List<CatagoryBean.DataBean> list = new ArrayList<>(); private Context context; public LeftAdapter(Context context, List<CatagoryBean.DataBean> list) { this.context = context; this.list = list; } @Override public LeftViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(context).inflate(R.layout.text_item, parent,false); return new LeftViewHolder(view); } @Override public void onBindViewHolder(LeftViewHolder holder, final int position) { if(po==position){ holder.textView.setTextColor(Color.RED); holder.textView.setBackgroundColor(Color.parseColor("#eeeeee")); }else { holder.textView.setTextColor(Color.BLACK); holder.textView.setBackgroundColor(Color.WHITE); } holder.textView.setText(list.get(position).getName()); holder.textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { listner.onItemClick(v,list.get(position).getCid()); po=position; notifyDataSetChanged(); } }); } private int po=0; @Override public int getItemCount() { return list.size(); } class LeftViewHolder extends RecyclerView.ViewHolder { public TextView textView; public LeftViewHolder(View itemView) { super(itemView); textView = (TextView) itemView.findViewById(R.id.left_title); } } //设置条目点击事件 private OnItemClickListner listner; public void setClick(OnItemClickListner listner){ this.listner=listner; } }
MyAdapter.java
package com.example.monthpractice1.adapter; import android.content.Context; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.bumptech.glide.Glide; import com.example.monthpractice1.R; import com.example.monthpractice1.bean.CatagoryBean; import com.example.monthpractice1.bean.GroupGoodsBean; import java.util.ArrayList; import java.util.List; /** * Created by mamiaomiao on 2018/2/27. * 图一对应显示图文的适配器 */ public class MyAdapter extends RecyclerView.Adapter<TextViewHolder> { private ArrayList<GroupGoodsBean.DataBean.ListBean> list = new ArrayList<>(); private Context context; public MyAdapter(Context context) { this.context = context; } public void addData(List<GroupGoodsBean.DataBean.ListBean> data){ this.list.addAll(data); notifyDataSetChanged(); } @Override public TextViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(context).inflate(R.layout.item, null); return new TextViewHolder(view); } @Override public void onBindViewHolder(TextViewHolder holder, int position) { holder.textView.setText(list.get(position).getName()); Glide.with(context).load(list.get(position).getIcon()).into(holder.img); } @Override public int getItemCount() { return list.size(); } }
OnItemClickListner.java
package com.example.monthpractice1.adapter; import android.view.View; /** * Created by mamiaomiao on 2018/2/27. */ public interface OnItemClickListner { void onItemClick(View view,int cid); }
TextViewHolder.java
package com.example.monthpractice1.adapter; import android.support.v7.widget.RecyclerView; import android.view.View; import android.widget.ImageView; import android.widget.TextView; import com.example.monthpractice1.R; /** * Created by mamiaomiao on 2018/2/27. */ public class TextViewHolder extends RecyclerView.ViewHolder { public TextView textView; public ImageView img; public TextViewHolder(View itemView){ super(itemView); textView=(TextView)itemView.findViewById(R.id.mytitle); img=(ImageView)itemView.findViewById(R.id.myimg); } }
![](https://avatar.csdn.net/3/8/6/3_frimary.jpg)
高仿京东分类页面实现
- hedong_77
- 2016年05月14日 11:17
- 1870
最近写了个小demo,仿京东的分类功能实现,网上看了有些用ListView并排,个人并不推荐这种方法,自己使用ListView+Fragment实现,OK,直接上代码 首先看主页面布局 xml...
安卓仿京东分类页面(1-3级)
- weixin_37389474
- 2017年08月25日 14:26
- 935
效果图: 先谈实现,再考虑优化,go –> 思路:左边一个listview,右边是一个填充页面的容器,之前考虑用fragment的replace方式管理fragment的添加,后来采用了vie...
-
怎么那么多人都说Python全栈工程师赚钱多?
是因为岗位人才缺乏吗?还是因为技术过硬?还是因为.......
![](https://ubmcmm.baidustatic.com/media/v1/0f000jlWjHuWuvuMPvRH60.jpg)
listview的分类,仿京东分类
- hyf97135
- 2016年09月14日 15:00
- 733
listview的分类,今天看到京东的app分类做的很ok,自己也尝试了下,效果实现了. //先上图,京东的,我自己的 //代码很容易就不过多做解释了. //主要的话就是两个方法的使用 /...
京东分类栏
- u013742084
- 2016年05月18日 14:42
- 760
今天把京东的分类栏给扒下来了,js部分是我自己写的,我不知道除了onmouseover和onmouseout之外,是否还有其他的方法,等以后遇到,会再来补充。 html部分: ...
[Android]仿京东手机端类别页
- stzy00
- 2015年08月24日 21:51
- 2626
[Android]仿京东手机端类别页京东手机端的类别标签页, 是一个左侧滑动可选择类别, 右侧一个类别明细的列表联动页面. 当用户选择左侧选项, 可在右侧显示更多选项来选择. 实现方式也不少. 最常见...
仿京东商城分类功能的实现
- ght199266
- 2015年03月12日 13:21
- 2415
前几天看到京东商城的分类页面,感觉还不错, 于是自己写了一个,说一下具体的功能吧。 1、点击左侧列表可以更新右边的布局,而且item可以滑动第一个 2、Listvew可以弹性滑动...
仿京东分类实现
- Star_Q
- 2017年11月22日 20:05
- 696
这篇主要就是一个仿京东分类的一篇,虽然代码比较多,认真看吧
Android 之仿京东分类(原理listview+fragment)
1.写一个fragmentimport android.os.Bundle; import android.support.v4.app.Fragment; import android.view.L...
- jky_yihuangxing
- 2016年08月16日 13:35
- 3770
仿京东App分类页面的实现
- qq_16131393
- 2016年03月16日 11:16
- 9519
今天群里有人问了关于仿京东App分类页面的实现,而我之前正好查过这方面的资料,手上正好有一个demo,正好分享给大家看看,个人觉得效果棒棒哒!首先来看效果图吧是不是很6呢,来分析这个demo的主体构成...
Android——仿京东淘宝分类页面
- xy8199
- 2017年11月22日 15:57
- 561
效果图: json在assets下 添加依赖: compile 'com.squareup.okhttp3:okhttp:3.8.1' compile 'com.facebook.fresc...
仿京东分类模块左侧分类条目效果
- u013680097
- 2016年10月09日 15:22
- 992
package com.frame.activity; import android.app.Activity; import android.os.Bundle; import android.v...
ANDROID高仿京东分类_类似京东分类界面源代码下载
http://dwtedx.com/itshare_443.html http://dwtedx.com/itshare_443.html http://dwtedx.com/itshar...
- u011904605
- 2016年09月22日 16:52
- 2021
iOS----仿京东分类菜单之UICollectionView内容
- iotjin
- 2015年10月15日 10:15
- 546
iOS仿京东分类菜单之UICollectionView内容 在上《iOS仿京东分类菜单实例实现》已经实现了大部分主体的功能,本文是针对右边集合列表进行修改扩展,使它达到分组的效果...
Jquery仿京东分类导航层简单实现
- smartsmile2012
- 2014年09月17日 09:05
- 2937
$(function () { var alink01 = $(".item > ul"); alink01.hover(function () { ...
[android进阶]仿京东app分类特效
- xiaolinxx
- 2014年03月25日 23:20
- 7691
在eoe论坛上看到某人高分求助,想实现京东分类效果 效果如图1: 图2: 1、首先是图1,点击某分类后,右侧滑动出覆盖层(过程有动画),如图二。 2、图一的分类列表在覆盖动画过程中,字...
高仿京东分类效果(Scroll+Fragment)
- Zheng_Jiao
- 2016年05月13日 16:46
- 3010
实现思路:首先说下布局,整个是一个横向的线性布局,左边是一个ScrollView,右边是一个FrameLayout, 在代码中动态向ScrollView中添加TextView,然后根据TextView...
android 实现仿美团点菜和京东分类导航
- MINGZHNGLEI
- 2017年01月11日 14:48
- 4071
android 实现仿美团点菜和京东分类导航 欢迎大家进群:574605026 开启我们的开发之旅 废话不多说,看图说话 当看到标题的时候,每个人都想知道,到底是个什么样子呢?会...
仿京东的分类页面
- qikaikai0324
- 2018年03月01日 11:17
- 57
package com.example.jingdong.View.Frament.Frament; import android.os.Bundle; import android.support...
使用golang抓取京东全部商品分类信息
- pssmart
- 2016年05月26日 11:52
- 697
package main import ( // "errors" "fmt" "io/ioutil" "net/http" "os" "regexp" "strings" ) ty...
Android仿京东左右分类
- u010107250
- 2015年03月15日 19:36
- 6999
最近看到很多购物商城都是采用了一种布局,左边是list列表右侧是商品的列表 所以练练手,其实很简单,左边就是一个ListView,右边是一个Fragment,Fragment的内容可以自己定...
-
原创
- 0
-
粉丝
- 1
-
喜欢
- 0
-
评论
- 0
文章存档
- 2018年4月
1篇
博主热门文章
- 京东分类
0