2024/5/31

所学时间:2小时

代码行数:100

博客园数:1篇

所学知识:

package com.example.kanglaojian;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import android.widget.BaseAdapter;

public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.MessageViewHolder> {
private List<String> messageList;

public MessageAdapter(List<String> messageList) {
this.messageList = messageList;
}

@NonNull
@Override
public MessageViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.iten_message, parent, false);
return new MessageViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull MessageViewHolder holder, int position) {
String message = messageList.get(position);
holder.messageTextView.setText(message);
}

@Override
public int getItemCount() {
return messageList.size();
}

public static class MessageViewHolder extends RecyclerView.ViewHolder {
TextView messageTextView;

public MessageViewHolder(View itemView) {
super(itemView);
messageTextView = itemView.findViewById(R.id.text_view_message);
}
}
}

posted @ 2024-05-31 20:34  为20岁努力  阅读(6)  评论(0编辑  收藏  举报