RecyclerView展开/折叠

时间:2019-05-27 15:00:28

标签: android material-design android-tablayout expandablerecyclerview

  1. 当我单击RecyclerView项时,我想展开/折叠下图所示的内容。
  2. 这与新的Android最近通话记录列表相同。仅当选择一个项目时,“呼叫”和“详细信息”或“发送消息”选项才可见。
  3. 图片: Images
  4. 这是我的 RecyclerViewAdapter 类,非常感谢:

    公共类RecyclerViewAdapter扩展了RecyclerView.Adapter {     上下文mContext;     列出mData;

    public RecyclerViewAdapter(Context mContext, List<Contact> mData) {
        this.mContext = mContext;
        this.mData = mData;
    }
    
    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View v;
        v = LayoutInflater.from(mContext).inflate(R.layout.item_contact, viewGroup, false);
        MyViewHolder viewHolder = new MyViewHolder(v);
    
        return viewHolder;
    }
    
    @Override
    public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, final int position) {
        myViewHolder.tvName.setText(mData.get(position).getName());
        myViewHolder.tvFname.setText(mData.get(position).getFname());
        myViewHolder.img.setImageResource(mData.get(position).getPhoto());
    }
    
    @Override
    public int getItemCount() {
        return mData.size();
    }
    
    public static class MyViewHolder extends RecyclerView.ViewHolder{
    
        private TextView tvName;
        private TextView tvFname;
        private ImageView img;
    
        public MyViewHolder(@NonNull View itemView) {
    
            super(itemView);
            tvName = (TextView)itemView.findViewById(R.id.tvName);
            tvFname = (TextView)itemView.findViewById(R.id.tvFname);
            img = (ImageView)itemView.findViewById(R.id.img_contact);
        }
    }
    

    }

0 个答案:

没有答案