分类adapter

package com.bawei.fenlei.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bawei.fenlei.R;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;

/**

  • @Author:苏羡c

  • @E-mail:

  • @Date:2019/3/23 14:10

  • @Description:描述信息
    */
    public class LeftRecyAdapter extends RecyclerView.Adapter<LeftRecyAdapter.ViewHolder> {
    Context context;
    String result;
    private HashMap<String,String> hashMap= new HashMap<>();

    public LeftRecyAdapter(Context context, String result) {
    this.context = context;
    this.result = result;
    }

    @NonNull
    @Override
    public LeftRecyAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
    View view = LayoutInflater.from(context).inflate(R.layout.left_view, null);
    ViewHolder viewHolder = new ViewHolder(view);
    return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull LeftRecyAdapter.ViewHolder viewHolder, final int i) {

     try {
         JSONObject jsonObject = new JSONObject(result);
         JSONArray result = jsonObject.getJSONArray("result");
         final String id = result.getJSONObject(i).getString("id");
         String name = result.getJSONObject(i).getString("name");
         viewHolder.left_text.setText(id);
         viewHolder.left_text.setText(name);
         viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 if (recyclerViewListener!=null){
                     recyclerViewListener.onclick(id);
                 }
             }
         });
     } catch (JSONException e) {
         e.printStackTrace();
     }
    

    }

    @Override
    public int getItemCount() {
    return result.length();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

     private TextView left_text;
    
     public ViewHolder(@NonNull View itemView) {
         super(itemView);
         left_text = itemView.findViewById(R.id.left_text);
     }
    

    }

    public interface RecyclerViewListener{
    void onclick(String id);
    }
    RecyclerViewListener recyclerViewListener;

    public void setRecyclerViewListener(RecyclerViewListener recyclerViewListener) {
    this.recyclerViewListener = recyclerViewListener;
    }
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值