ListPatientCursorAdapter listAdapter = new ListPatientCursorAdapter(this, R.layout.patient_list, cursor);
setListAdapter(listAdapter);
startManagingCursor(cursor);
Custom List Adapter :
class ListPatientCursorAdapter extends ResourceCursorAdapter {
public ListPatientCursorAdapter(Context context, int layout, Cursor c) {
super(context, layout, c);
}
@Override
public View newView(Context context, Cursor cur, ViewGroup parent) {
LayoutInflater li = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
return li.inflate(R.layout.patient_list_row, parent, false);
}
@Override
public void bindView(View v, Context context, final Cursor _c) {
TextView tvId = (TextView)v.findViewById(R.id.tvId);
final Integer id = _c.getInt(_c.getColumnIndex(Patient.PatientField.ID));
TextView tvFirstName = (TextView) v.findViewById(R.id.tvFirstName);
tvFirstName.setText(_c.getString(_c
.getColumnIndex(Patient.PatientField.FIRSTNAME)));
TextView tvMiddleName = (TextView) v
.findViewById(R.id.tvMiddleName);
tvMiddleName.setText(_c.getString(_c
.getColumnIndex(Patient.PatientField.MIDDLENAME)));
TextView tvLastName = (TextView) v.findViewById(R.id.tvLastName);
tvLastName.setText(_c.getString(_c
.getColumnIndex(Patient.PatientField.LASTNAME)));
TextView tvLastUpdate = (TextView) v
.findViewById(R.id.tvLastUpdate);
CheckBox cbFollowUp = (CheckBox) v.findViewById(R.id.cbFollowUp);
cbFollowUp
.setChecked(_c.getInt(_c
.getColumnIndex(Patient.PatientField.FOR_FOLLOWUP)) == 0 ? false
: true);
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(_c.getLong(_c
.getColumnIndex(Patient.PatientField.UPDATE_DATE)));
tvLastUpdate.setText(sdf.format(cal.getTime()));
v.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
processSelectedId(id);
}
});
}
}
List View :
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:divider="#FFFFFF"
android:dividerHeight="0sp"
android:scrollbars="none" />
android:id="@id/android:empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5px"
android:gravity="center"
android:text="No Patient Record." >
List Row :
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
android:id="@+id/tvId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:visibility="gone"/>
android:id="@+id/llPatient"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
android:id="@+id/tvLastName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Puti"
android:textAppearance="?android:attr/textAppearanceLarge" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" "
android:textAppearance="?android:attr/textAppearanceMedium" />
android:id="@+id/tvFirstName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Kyle"
android:textAppearance="?android:attr/textAppearanceMedium" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" "
android:textAppearance="?android:attr/textAppearanceMedium" />
android:id="@+id/tvMiddleName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Amousy"
android:textAppearance="?android:attr/textAppearanceMedium" />
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Last Update"
android:textAppearance="?android:attr/textAppearanceMedium" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" "
android:textAppearance="?android:attr/textAppearanceMedium" />
android:id="@+id/tvLastUpdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Last Update" />
android:id="@+id/cbFollowUp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:enabled="false"
android:text="For Follow Up" />