generated from dellevin/template
53 lines
1.5 KiB
Java
53 lines
1.5 KiB
Java
package top.iletter.lvnote;
|
|
|
|
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;
|
|
|
|
public class NoteAdapter extends RecyclerView.Adapter<NoteAdapter.ViewHolder> {
|
|
|
|
private final List<String> notes;
|
|
|
|
public NoteAdapter(List<String> notes) {
|
|
this.notes = notes;
|
|
}
|
|
|
|
@NonNull
|
|
@Override
|
|
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
View view = LayoutInflater.from(parent.getContext())
|
|
.inflate(R.layout.item_note, parent, false);
|
|
return new ViewHolder(view);
|
|
}
|
|
|
|
@Override
|
|
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
|
|
String note = notes.get(position);
|
|
String[] parts = note.split(" · ");
|
|
holder.title.setText(parts[0]);
|
|
holder.content.setText(parts.length > 1 ? parts[1] : "无内容");
|
|
holder.time.setText("2024-02-09 15:30");
|
|
}
|
|
|
|
@Override
|
|
public int getItemCount() {
|
|
return notes.size();
|
|
}
|
|
|
|
static class ViewHolder extends RecyclerView.ViewHolder {
|
|
TextView title, content, time;
|
|
|
|
ViewHolder(View itemView) {
|
|
super(itemView);
|
|
title = itemView.findViewById(R.id.tv_note_title);
|
|
content = itemView.findViewById(R.id.tv_note_content);
|
|
time = itemView.findViewById(R.id.tv_note_time);
|
|
}
|
|
}
|
|
} |