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

时间:2018-10-11 08:52:47

标签: android list android-recyclerview autocompletetextview android-chips

我有一个列表,其中每一行将包含多个芯片。 在每一行中,我都可以键入任何内容,然后就会出现建议,如果我选择了任何建议,则芯片会像自动完成文本视图一样添加到同一行中。

我尝试了很多事情,例如以线性布局动态添加视图等,但是没有得到解决方案。

如果有人知道该怎么做,我表示感谢。

1 个答案:

答案 0 :(得分:0)

这是我的代码成功运行;

包com.example.masterappinc; 公共类Judgedetailadapter扩展了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();
}

}

希望这次跑步!