美文网首页
RecyclerView.Adapter

RecyclerView.Adapter

作者: 余炳高笔记 | 来源:发表于2023-07-05 21:09 被阅读0次

    笔记,下次找的时候方便一些.

    import android.view.View;

    import android.view.ViewGroup;

    import android.widget.TextView;

    import androidx.recyclerview.widget.RecyclerView;

    import java.util.List;

    public class NameAdapterextends RecyclerView.Adapter {

    private ListmNames;

        public NameAdapter(List names) {

    this.mNames = names;

        }

    @Override

        public NameAdapter.HolderonCreateViewHolder(ViewGroup parent, int viewType) {

    View view = View.inflate(parent.getContext(), R.layout.item, null);

            Holder holder =new Holder(view);

            return holder;

        }

    @Override

        public void onBindViewHolder(NameAdapter.Holder holder, int position) {

    holder.text.setText(mNames.get(position));

            holder.itemView.setTag(position);

        }

    @Override

        public int getItemCount() {

    return mNames.size();

        }

    public class Holderextends RecyclerView.ViewHolder {

    private final TextViewtext;

            public Holder(View itemView) {

    super(itemView);

                text = itemView.findViewById(R.id.text_name);

            }

    }

    }

    相关文章

      网友评论

          本文标题:RecyclerView.Adapter

          本文链接:https://www.haomeiwen.com/subject/bxnkudtx.html