0
  1. 当我单击 RecyclerView 的一项时,我想展开/折叠如下图所示的内容。
  2. 这与新的 Android 最近通话记录列表的效果相同。选项“CALL”和“DETAILS”或“SEND MESSAGE”仅在选择项目时可见。
  3. 图片: 图片
  4. 这是我的RecyclerViewAdapter类,非常感谢:

    公共类 RecyclerViewAdapter 扩展 RecyclerView.Adapter { Context 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);
        }
    }
    

    }

4

0 回答 0