RecyclerView Android Json

RecyclerView Android Json,android,json,android-recyclerview,retrofit,Android,Json,Android Recyclerview,Retrofit,如何使用改装在RecylerView中设置数据。我已尝试过,但未能成功执行 这是我的代码: JSON数据是: { "model": [ { "id": "1", "brand_name": "Audi", "brand_logo": "1495456122.", }, { "id": "3", "brand_name": "BMW", "brand_logo": "1495451144.", } ] } BrandSelectActivity.java

如何使用改装RecylerView中设置数据。我已尝试过,但未能成功执行

这是我的代码:

JSON数据是:

 {
"model": [
{
  "id": "1",
  "brand_name": "Audi",
  "brand_logo": "1495456122.",

},
{
  "id": "3",
  "brand_name": "BMW",
  "brand_logo": "1495451144.",

}
]
}    
BrandSelectActivity.java

   public class BrandSelectActivity extends AppCompatActivity implements View.OnClickListener {
ProgressDialog pDialog;

Button btn_addVehicle;
BrandListRecyclerAdapter adapter;


RecyclerView recyclerView_brand;
public ImageView carBrandImg;
public TextView carBrandName;

private static String TAG = BrandSelectActivity.class.getSimpleName();



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_brand_select);
    carBrandImg = (ImageView)findViewById(R.id.carBrandImg);
    carBrandName = (TextView)findViewById(R.id.carBrandName);
    recyclerView_brand = (RecyclerView) findViewById(R.id.recycler_view);
    pDialog = new ProgressDialog(getApplicationContext());
    pDialog.setCancelable(true);
    pDialog.setMessage("Please Wait...");
    pDialog.show();

    ArrayList<BrandModel> brandModelArrayList = new ArrayList<BrandModel>();   

    BrandListRecyclerAdapter brandAdapter = new BrandListRecyclerAdapter(BrandSelectActivity.this, brandModelArrayList);
    RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
    recyclerView_brand.setLayoutManager(mLayoutManager);
    recyclerView_brand.setAdapter(brandAdapter);


    brandAdapter.setItemClickListener(new BrandListRecyclerAdapter.MyClickListerer() {
        @Override
        public void onItemClick(int position, View view) {
            Intent sosIntent = new Intent(BrandSelectActivity.this, ModelSelectActivity.class);
            startActivity(sosIntent);
            overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left);
        }
    });

    callBrandSelect();

}


    private void callBrandSelect() {

    ApiInterface apiService = 
   ApiClient.getClient().create(ApiInterface.class);

    Call<BrandSelectResponse> call = apiService.saveBrand("1");
    call.enqueue(new Callback<BrandSelectResponse>() {
        @Override
        public void onResponse(Call<BrandSelectResponse> call, retrofit2.Response<BrandSelectResponse> response) {
            BrandSelectResponse br=  response.body();
            List<BrandSelectResponse.ModelBean> modelList = br.getModel();

            modelList.size();
            modelList.get(0).getBrand_logo();
            modelList.get(0).getBrand_name();


               pb.dismiss();
        }

        @Override
        public void onFailure(Call<BrandSelectResponse>call, Throwable t) {

            Toast.makeText(BrandSelectActivity.this,"Opps ..!!Failed to 
     connect to our server.. Try Again later..",Toast.LENGTH_SHORT).show();

            Log.e(TAG, t.toString());
        }
    });
    }

@Override
public void onClick(View v) {
}
 }
公共类BrandSelectActivity扩展AppCompatActivity实现View.OnClickListener{
ProgressDialog;
按钮btn_添加车辆;
BrandListRecyclerAdapter适配器;
RecyclerView RecyclerView_品牌;
公共图像视图carBrandImg;
公共文本视图名称;
私有静态字符串标记=BrandSelectActivity.class.getSimpleName();
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u brand\u select);
carBrandImg=(ImageView)findViewById(R.id.carBrandImg);
carBrandName=(TextView)findViewById(R.id.carBrandName);
recyclerView\u brand=(recyclerView)findViewById(R.id.recycler\u视图);
pDialog=newprogressdialog(getApplicationContext());
pDialog.setCancelable(真);
setMessage(“请稍候…”);
pDialog.show();
ArrayList brandModelArrayList=新的ArrayList();
BrandListRecyclerAdapter brandAdapter=新的BrandListRecyclerAdapter(BrandSelectActivity.this,brandModelArrayList);
RecyclerView.LayoutManager mLayoutManager=新的LinearLayoutManager(getApplicationContext());
recyclerView_brand.setLayoutManager(mLayoutManager);
recyclerView_brand.setAdapter(品牌适配器);
brandAdapter.setItemClickListener(新的BrandListRecyclerAdapter.MyClickListener(){
@凌驾
公共虚空onItemClick(内部位置,视图){
Intent sosIntent=新的Intent(BrandSelectActivity.this,ModelSelectActivity.class);
星触觉(sosIntent);
覆盖转换(R.anim.slide\u in\u right,R.anim.slide\u out\u left);
}
});
callBrandSelect();
}
私有void callBrandSelect(){
API接口API服务=
ApiClient.getClient().create(apinterface.class);
Call Call=apiService.saveBrand(“1”);
call.enqueue(新回调(){
@凌驾
公共void onResponse(呼叫,改装2.响应){
BrandSelectResponse br=response.body();
List modelList=br.getModel();
modelList.size();
modelList.get(0).getBrand_logo();
modelList.get(0).getBrand_name();
pb.dispose();
}
@凌驾
失败时公共无效(Callcall、Throwable t){
Toast.makeText(BrandSelectActivity.this,“Opps..!!未能
连接到我们的服务器..稍后再试..“,Toast.LENGTH_SHORT).show();
Log.e(TAG,t.toString());
}
});
}
@凌驾
公共void onClick(视图v){
}
}
BrandListRecyclerAdapter.java

  public class BrandListRecyclerAdapter extends RecyclerView.Adapter<BrandListRecyclerAdapter.MyViewHolder> {

    Context mcontext;
    List<BrandSelectResponse> brandModelArrayList;
    public  LayoutInflater inflater;
    public static MyClickListerer myClickListerer;


public BrandListRecyclerAdapter(Context context, ArrayList<BrandSelectResponse> brandModelArrayList) {
    this.mcontext = context;
   this.brandModelArrayList=brandModelArrayList;
 }



@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

    View view = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.row_brand, parent, false);

    return new MyViewHolder(view);
}

@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
    BrandSelectResponse current = brandModelArrayList.get(position);
    holder.setData((BrandSelectResponse) brandModelArrayList,position);
    holder.carBrandName.setText(current.getBrand_name());
     holder.carBrandImg.setImageResource(current.getBrand_logo());
}

public interface MyClickListerer {
    void onItemClick(int position, View view);
}

public void setItemClickListener(MyClickListerer myClickListerer) {
    this.myClickListerer = myClickListerer;
}

@Override
public int getItemCount() {
    return brandModelArrayList.size();
}
  public class MyViewHolder extends RecyclerView.ViewHolder implements 
   View.OnClickListener {
    public ImageView carBrandImg;
    public TextView carBrandName;
    BrandSelectResponse brandModelArrayList;
    LinearLayout current;
    int position;

    public MyViewHolder(View itemView) {

        super(itemView);
        carBrandImg = (ImageView) itemView.findViewById(R.id.carBrandImg);
        carBrandName = (TextView) itemView.findViewById(R.id.carBrandName);



    }


    public void setData(BrandSelectResponse current, int position) {

        carBrandName.setText(brandModelArrayList.getBrand_name());
        carBrandImg.setImageResource(brandModelArrayList.getBrand_logo());

        this.position = position;
        this.brandModelArrayList = current;
    }


    @Override
    public void onClick(View v) {
        myClickListerer.onItemClick(getAdapterPosition(), v);
    }
}
  } 
公共类BrandListRecyclerAdapter扩展了RecyclerView.Adapter{
语境;
列出brandModelArrayList;
公共场所;充气机;
公共静态MyClickLister MyClickLister;
公共BrandListRecyclerAdapter(上下文上下文,ArrayList brandModelArrayList){
this.mcontext=上下文;
this.brandModelArrayList=brandModelArrayList;
}
@凌驾
公共MyViewHolder onCreateViewHolder(视图组父级,int-viewType){
View=LayoutInflater.from(parent.getContext())
.充气(R.layout.row_品牌、母公司、假);
返回新的MyViewHolder(视图);
}
@凌驾
公共无效onBindViewHolder(MyViewHolder,int位置){
BrandSelectResponse current=brandModelArrayList.get(位置);
holder.setData((BrandSelectResponse)brandModelArrayList,位置);
holder.carBrandName.setText(current.getBrand_name());
holder.carBrandImg.setImageResource(current.getBrand_logo());
}
公共界面MyClickLister{
void onItemClick(int位置,视图);
}
public void setItemClickListener(MyClickListener MyClickListener){
this.myclicklister=myclicklister;
}
@凌驾
public int getItemCount(){
返回brandModelArrayList.size();
}
公共类MyViewHolder扩展了RecyclerView.ViewHolder实现
View.OnClickListener{
公共图像视图carBrandImg;
公共文本视图名称;
BrandSelectResponse brandModelArrayList;
线性布置电流;
内部位置;
公共MyViewHolder(查看项目视图){
超级(项目视图);
carBrandImg=(ImageView)itemviewbyd(R.id.carBrandImg);
carBrandName=(TextView)itemView.findViewById(R.id.carBrandName);
}
公共无效设置数据(BrandSelectResponse当前,整数位置){
carBrandName.setText(brandModelArrayList.getBrand_name());
carBrandImg.setImageResource(brandModelArrayList.getBrand_logo());
这个位置=位置;
this.brandModelArrayList=当前;
}
@凌驾
公共void onClick(视图v){
myclicklister.onItemClick(getAdapterPosition(),v);
}
}
} 
BrandSelectResponse.java

public class BrandSelectResponse implements Serializable{


private List<ModelBean> model;

public BrandSelectResponse(List<ModelBean> model) {
    this.model = model;
}

public List<ModelBean> getModel() {
    return model;
}

public void setModel(List<ModelBean> model) {
    this.model = model;
}

public static class ModelBean {


    private String id;
    private String brand_name;
    private String brand_logo;


    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getBrand_name() {
        return brand_name;
    }

    public void setBrand_name(String brand_name) {
        this.brand_name = brand_name;
    }

    public String getBrand_logo() {
        return brand_logo;
    }

    public void setBrand_logo(String brand_logo) {
        this.brand_logo = brand_logo;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

  }
  }
公共类BrandSelectResponse实现可序列化{
私有列表模型;
公共品牌SelectResponse(列表模型){
this.model=模型;
}
公共列表getModel(){
收益模型;
}
公共void集合模型(列表模型){
this.model=模型;
}
公共静态类ModelBean{
私有字符串id;
私有字符串品牌名称;
私人字符串品牌标识;
公共字符串getId(){
返回id;
}
公共无效集合id(字符串id){
this.id=id;
}
公共字符串getBrand_name(){
返回品牌名称;
}
公共品牌名称(字符串品牌名称){
this.brand\u name=品牌名称;
}
公共字符串getBrand_徽标(){
返回品牌标识;
}
公共品牌标识(字符串品牌标识){
this.brand_logo=品牌_logo;
}
公共字符串getDescription(){
返回说明;
}
公共void集合描述(字符串描述){
this.description=descrip