次のようなカスタムアダプターがあります。私の目的は、今後の予定と過去の予定を 1 つに表示することですListView
。だから私は一緒に行くことにしましCustom ArrayAdapter
た。しかし、 getView() が呼び出されない理由がわかりません。また、オーバーライドgetCount()
すると、サイズとして 50 が得られますitems
public class AppointmentListAdapter extends ArrayAdapter<Item> {
List<Item> items;
private Context context;
private LayoutInflater vi;
public static boolean pastApptSectionDrawn = false;
private int healowUserId, portalUserId;
public AppointmentListAdapter(Context context, List<Item> items, int healowUserId, int portalUserId){
super(context, 0, items);
this.context = context;
this.items = items;
vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.healowUserId = healowUserId;
this.portalUserId = portalUserId;
}
@Override
public int getCount() {
return this.items.size();
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
System.out.println("getView of AppointmentListAdapter...");
View v = convertView;
final Item item = items.get(position);
if(item != null){
if(item.isSection()){
ApptListSection si = (ApptListSection)item;
String title = si.getTitle();
v = vi.inflate(R.layout.appointment_list_section, null);
v.setOnClickListener(null);
v.setOnLongClickListener(null);
v.setLongClickable(false);
View apptSectionShape = v.findViewById(R.id.apptSectionShape);
TextView apptSectionTitle = (TextView) v.findViewById(R.id.apptSectionTitle);
if(apptSectionShape != null)
apptSectionShape.setBackgroundResource(si.getBgResourceId());
if(apptSectionTitle != null)
apptSectionTitle.setText(si.getTitle());
final TextView sectionView = (TextView) v.findViewById(R.id.list_item_section_text);
sectionView.setText(title);
if(Global.NO_UPCOMING_APPT.equals(title)){
final LinearLayout sectionItemLayout = (LinearLayout) v.findViewById(R.id.section_item_layout);
sectionItemLayout.setMinimumHeight(CommonUtilities.getDPEquivalentPixels(this.context, 60F));
sectionItemLayout.setBackgroundColor(Color.WHITE);
sectionItemLayout.setGravity(Gravity.CENTER);
sectionView.setTextSize(18);
sectionView.setTextColor(Color.BLACK);
sectionView.setBackgroundColor(Color.WHITE);
sectionView.setGravity(Gravity.CENTER);
}
}else{
Appointment appt = (Appointment)item;
v = vi.inflate(R.layout.list_items_appointments_loading, null);
final TextView appointmentDate = (TextView) v.findViewById(R.id.appointmentDate);
final TextView practiceName = (TextView) v.findViewById(R.id.txtApptProviderName);
final TextView apptReason = (TextView) v.findViewById(R.id.txtApptReason);
final TextView txtDayOfMonth = (TextView) v.findViewById(R.id.txtDayOfMonth);
final TextView txtMonthYear = (TextView) v.findViewById(R.id.txtMonthYear);
final TextView txtDayOfWeek = (TextView) v.findViewById(R.id.txtDayOfWeek);
final TextView txtApptTime = (TextView) v.findViewById(R.id.txtApptTime);
int colorIndCode;
if(appt.isPastAppointment()){
colorIndCode = Color.parseColor("#e4a83c");
}else{
colorIndCode = Color.parseColor("#69cbd8");
}
txtDayOfMonth.setTextColor(colorIndCode);
txtDayOfWeek.setTextColor(colorIndCode);
if(appointmentDate != null){
Calendar cal = Calendar.getInstance();
Date startDateTime = appt.getStartDateTime();
cal.setTime(startDateTime);
//StringBuilder timeBuilder = new StringBuilder(new SimpleDateFormat("MMM").format(startDateTime)+ " " + cal.get(Calendar.DAY_OF_MONTH)+ ", " + cal.get(Calendar.YEAR)+ " ");
StringBuilder timeBuilder = new StringBuilder("");
int hour = cal.get(Calendar.HOUR);
timeBuilder.append(((hour<10)?"0":"") + hour + ":");
int mins = cal.get(Calendar.MINUTE);
timeBuilder.append(((mins<10)?"0":"") + mins + " ");
timeBuilder.append(cal.get(Calendar.AM_PM) == Calendar.AM ? "AM":"PM");
appointmentDate.setText(timeBuilder.toString());
txtDayOfMonth.setText((cal.get(Calendar.DAY_OF_MONTH)));
String month_year = new SimpleDateFormat("MMM").format(startDateTime) + " " + cal.get(Calendar.YEAR);
txtMonthYear.setText(month_year);
txtDayOfWeek.setText(new SimpleDateFormat("EEEE").format(startDateTime));
txtApptTime.setText(timeBuilder.toString());
}
if(practiceName != null){
practiceName.setText(appt.getUfname() + " " + appt.getUlname());
}
if(apptReason != null){
apptReason.setText(appt.getReason());
}
//Write the code to decide on note & reminder symbol
}
}
return v;
}
}`