在每行回收视图中动态添加芯片。

问题描述 投票:1回答:1

我有一个列表,其中每一行将由多个芯片组成.在每一行,我可以输入任何东西,建议会来,如果我选择任何一个建议,然后芯片将被添加到同一行,就像自动完成文本视图。

我尝试了很多东西,如在线性布局和其他动态添加视图,但没有得到解决。

我很感激,如果有人知道如何做到这一点。

android list android-recyclerview autocompletetextview android-chips
1个回答
0
投票

这是我成功运行的代码。

package com.example.masterappinc;public class Judgedetailadapter extends RecyclerView.Adapter {。

Judgedetailreturn judgedetailreturn;
List<Judgedetailreturn> judgelist;
Context context;

public Judgedetailadapter(List<Judgedetailreturn> judgelist, Context context) {
    this.judgelist = judgelist;
    this.context = context;

}

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

    LayoutInflater inflater =LayoutInflater.from(context);
    View view= inflater.inflate(R.layout.cardviewjudgedetail,parent,false);

    return new MyViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull final MyViewHolder holder, int position) {
    final Judgedetailreturn judgedetailreturn1=judgelist.get(position);
    holder.name.setText(judgedetailreturn1.getName());
    String ide = judgedetailreturn1.getId();
    holder.id.setText(ide);
    holder.company.setText(judgedetailreturn1.getCompany());
    holder.mobno.setText(judgedetailreturn1.getMobno());
    holder.domain.setText(judgedetailreturn1.getDomain());
    holder.email.setText(judgedetailreturn1.getEmail());

    Firebase mref = new Firebase("https://master-app-inc.firebaseio.com/judgeid/"+ide+"/StudentIDalloted");
    mref.addChildEventListener(new ChildEventListener() {
        @Override
        public void onChildAdded(DataSnapshot dataSnapshot, String s) {


            Chip chip=new Chip(holder.chipGroup.getContext());
            chip.setText(dataSnapshot.getValue().toString());
            holder.chipGroup.addView(chip);

        }

        @Override
        public void onChildChanged(DataSnapshot dataSnapshot, String s) {

        }

        @Override
        public void onChildRemoved(DataSnapshot dataSnapshot) {

        }

        @Override
        public void onChildMoved(DataSnapshot dataSnapshot, String s) {

        }

        @Override
        public void onCancelled(FirebaseError firebaseError) {

        }
    });
}

@Override
public int getItemCount() {
    return judgelist.size();
}

public class MyViewHolder extends RecyclerView.ViewHolder {

    ChipGroup chipGroup;
    TextView name,id,email,mobno,company,domain;

    public MyViewHolder(@NonNull View itemView) {
        super(itemView);
        name = itemView.findViewById(R.id.namejudegedetail);
        id = itemView.findViewById(R.id.judgeidjudegedetail);
        email = itemView.findViewById(R.id.emailidjudegedetail);
        mobno = itemView.findViewById(R.id.mobilenojudgedetail);
        company = itemView.findViewById(R.id.companynamejudegedetail);
        domain= itemView.findViewById(R.id.domainjudgedetail);
        chipGroup = itemView.findViewById(R.id.chipgrp);

    }
}
public void toast(String x){
    Toast.makeText(context,x,Toast.LENGTH_SHORT).show();
}

}

希望这个运行!

© www.soinside.com 2019 - 2024. All rights reserved.