6.3

public class MoodRecordAdapter extends ArrayAdapter<MoodRecord> {
private int resourceId;

public MoodRecordAdapter(Context context, List<MoodRecord> objects) {
super(context, 0, objects);
this.resourceId = android.R.layout.simple_list_item_2;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
MoodRecord record = getItem(position);
View view;
if (convertView == null) {
view = LayoutInflater.from(getContext()).inflate(resourceId, parent, false);
} else {
view = convertView;
}

TextView text1 = view.findViewById(android.R.id.text1);
TextView text2 = view.findViewById(android.R.id.text2);

text1.setText("Date: " + record.getDate());
text2.setText("Mood: " + record.getMood());

return view;
}
}
posted @ 2024-06-04 22:45  涨涨涨张  阅读(4)  评论(0编辑  收藏  举报