我的Custome ArrayAdapter:它执行它应该执行的操作但仅显示特定表的最后一条记录。我需要它来显示所有记录
public class RecordAdapter extends ArrayAdapter<RecordData> {
Context context;
int layoutResourceId;
RecordData data[] = null;
private LayoutInflater inflater;
public RecordAdapter(Context context, int layoutResourceId, RecordData[] data) {
super(context, layoutResourceId, data);
inflater = LayoutInflater.from(context);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
RecordHolder holder = null;
if (row == null) {
LayoutInflater inflater = ((Activity) context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new RecordHolder();
holder.txtDate = (TextView) row.findViewById(R.id.txtDate);
row.setTag(holder);
} else {
holder = (RecordHolder) row.getTag();
}
RecordData record_item = data[position];
holder.txtDate.setText(record_item.recDate);
return row;
}
static class RecordHolder {
TextView txtDate;
}
}
我的OnClickListener:
String dateToSee = mDisplayDate.getText().toString().trim();
MyRecordsDatabaseHandler db = new MyRecordsDatabaseHandler(this);
// Querying all items
List<RecordToDoActivity> items = db.getRecord(dateToSee);
for (RecordToDoActivity ti : items) {
for (int i = 0; i <= items.size(); i++) {
display_record_dateEditText.setText(ti.getDate());
display_record_timeEditText.setText(ti.getTime());
display_record_glucoseEditText.setText(ti.getReading());
display_record_glucoseTimeEditText.setText(ti.getReadtime());
display_record_mealTimeEditText.setText(ti.getMealTime());
display_record_medsEditText.setText(ti.getMeds());
//display_record_insulin_unit_text.setText(ti.get());
display_record_moodEditText.setText(ti.getMood());
display_record_weatherEditText.setText(ti.getWeather());
display_record_notesEditText.setText(ti.getNote()
);
}
}
if (!display_record_dateEditText.getText().toString().trim().equals("")&&
!display_record_timeEditText.getText().toString().trim().equals("")&&
!display_record_glucoseEditText.getText().toString().trim().equals("")&&
!display_record_glucoseTimeEditText.getText().toString().trim().equals("")&&
!display_record_mealTimeEditText.getText().toString().trim().equals("")&&
!display_record_medsEditText.getText().toString().trim().equals("")&&
!display_record_moodEditText.getText().toString().trim().equals("")&&
!display_record_weatherEditText.getText().toString().trim().equals("")&&
!display_record_notesEditText.getText().toString().trim().equals("") ) {
RecordData record_data[] = new RecordData[] {
new RecordData("Date: "+display_record_dateEditText.getText().toString().trim()+ "\n"+
"Time: "+display_record_timeEditText.getText().toString().trim()+ "\n"+
"Reading: "+display_record_glucoseEditText.getText().toString().trim()+ "\n"+
"Reading Time: "+display_record_glucoseTimeEditText.getText().toString().trim()+ "\n"+
"Meal: "+display_record_mealTimeEditText.getText().toString().trim()+ "\n"+
"Medication: "+display_record_medsEditText.getText().toString().trim()+ "\n"+
"Mood: "+display_record_moodEditText.getText().toString().trim()+ "\n"+
"Weather: "+display_record_weatherEditText.getText().toString().trim()+ "\n"+
"Notes: "+display_record_notesEditText.getText().toString().trim()),
};
RecordAdapter adapter = new RecordAdapter(this,
R.layout.listview_record_row, record_data);
listView1 = (ListView) findViewById(R.id.listView1);
listView1.setAdapter(adapter);
}//end ITEM_ONE if statement
我已经单独尝试了每个项目,它们都显示数据。但我无法弄清楚如何让它将所有记录显示在One list view
中ListView是封装在LinearLayout中的普通ListView:
帮助....我真的坚持这个。感谢