Android——关键字搜索商品

  • Post author:
  • Post category:其他


<uses-permission android:name="android.permission.INTERNET" />

adapter——RVAdapter
public class RVAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements View.OnClickListener{

    private Context context;
    private List<JavaBean.DataBean> list;

    public RVAdapter(Context context, List<JavaBean.DataBean> list) {
        this.context = context;
        this.list = list;
    }



    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item,null);
        MyHolder myHolder = new MyHolder(view);
        view.setOnClickListener(this);
        return myHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof MyHolder){
            MyHolder myHolder = (MyHolder) holder;
            ImageLoader.getInstance().displayImage(list.get(position).getImages(),myHolder.img,MyApplication.getOptons());
            myHolder.name.setText(list.get(position).getTitle());

            myHolder.name.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    listener.onItemClick();
                }
            });
        }
    }

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

    @Override
    public void onClick(View view) {
        if (listener!=null){
            listener.onItemClick();
        }
    }

    class MyHolder extends RecyclerView.ViewHolder{

        private ImageView img;
        private TextView name;


        public MyHolder(View itemView) {
            super(itemView);
            //找控件
            img = itemView.findViewById(R.id.image);
            name = itemView.findViewById(R.id.name);

        }
    }

    public interface OnClickListener{
        void onItemClick();
    }

    public OnClickListener listener;

    public void setOnItemClickListener(OnClickListener listener){
        this.listener = listener;
    }

}
bean——JavaBean 
public class JavaBean {
private String msg;
private String code;
private String page;
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 String getPage() {
    return page;
}

public void setPage(String page) {
    this.page = page;
}

public List<D



版权声明:本文为qq_39714504原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。