笔记,下次找的时候方便一些.
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);
}
}
}
网友评论