码迷,mamicode.com
首页 > 编程语言 > 详细

Rxjava列表跳详情

时间:2018-01-03 22:32:26      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:schedule   err   present   line   mode   androi   resource   ids   serve   

 //详情
    public  static final  String XQURL="product/getProductDetail";

@GET(Api.XQURL)
    Flowable<XqBean> xqbean(@Query("pid") String pid ,@Query("resource") String resource);


model

public class XqModel implements IXqModel {

    @Override
    public void getXq(String pid, final OnNetListener<XqBean> onNetListener) {

        ServerApi serverApi = RetrofitHelper.getServerApi();
        Flowable<XqBean> xqbean = serverApi.xqbean(pid,"android");
        xqbean.doOnSubscribe(new Consumer<Subscription>() {
            @Override
            public void accept(Subscription subscription) throws Exception {

            }
        })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<XqBean>() {
                    @Override
                    public void accept(XqBean xqBean) throws Exception {
                        onNetListener.onSuccess(xqBean);
                    }
                });
    }
}

  

p层
public class IXqPresenter {
    private IXqModel iXqModel;
    private IXqActivity iXqActivity;

    public IXqPresenter(IXqActivity iXqActivity) {
        this.iXqActivity = iXqActivity;
        iXqModel = new XqModel();
    }
    public void getxq(String pid){
        iXqModel.getXq(pid, new OnNetListener<XqBean>() {
            @Override
            public void onSuccess(XqBean xqBean) {
                iXqActivity.onxq(xqBean);
            }

            @Override
            public void onFailure(Exception e) {

            }
        });
    }
}

列表适配器
public class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context context;
    private List<ShowBean.TuijianBean.ListBean> list;
    private LayoutInflater inflater;
    private OnItemClickListener onItemClickListener;


    //跳转到详情页的操作
    public interface OnItemClickListener{
        void onItem(String str);
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener){
        this.onItemClickListener = onItemClickListener;
    }

    public MyAdapter(Context context, List<ShowBean.TuijianBean.ListBean> list) {
        this.context = context;
        this.list = list;
        inflater = LayoutInflater.from(context);
    }



    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflate = inflater.inflate(R.layout.item1, parent, false);
        return new MyViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        MyViewHolder myViewHolder = (MyViewHolder) holder;
        final ShowBean.TuijianBean.ListBean listBean = list.get(position);
        myViewHolder.sim.setImageURI(listBean.getImages());
        myViewHolder.tv1.setText(listBean.getTitle());

        //跳转到详情页
        myViewHolder.liner.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int pid = listBean.getPid();
                onItemClickListener.onItem(pid+"");
        }
        });

    }

    @Override
    public int getItemCount() {
        if (list == null){
            return 0;
        }
        return list.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {

        public SimpleDraweeView sim;
        public TextView tv1;
        private final LinearLayout liner;

        public MyViewHolder(View itemView) {
            super(itemView);
            liner = itemView.findViewById(R.id.liner);
            sim = itemView.findViewById(R.id.sim);
            tv1 = itemView.findViewById(R.id.tv1);

        }
    }

}

  

列表主类
适配器点击事件
adapter.setOnItemClickListener(new MyAdapter.OnItemClickListener() {
            @Override
            public void onItem(String str) {
                Intent intent = new Intent(MainActivity.this, XqActivity.class);
                intent.putExtra("pid",str);
                startActivity(intent);
            }
        });

详情主类
接收传过来的id
 Intent intent = getIntent();
        String pid = intent.getStringExtra("pid");
        Toast.makeText(this, pid, Toast.LENGTH_SHORT).show();
        IXqPresenter iXqPresenter = new IXqPresenter(this);
        iXqPresenter.getxq(pid);


@Override
public void onxq(XqBean xqBean) {
XqBean.DataBean data = xqBean.getData();
String images = data.getImages();
String[] split = images.split("\\|");
mXqSim.setImageURI(split[0]);
mXqTv.setText(data.getTitle());
mXqPrice.setText("$"+data.getPrice()+"");
}

  

Rxjava列表跳详情

标签:schedule   err   present   line   mode   androi   resource   ids   serve   

原文地址:https://www.cnblogs.com/wsq110/p/8185595.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!