Here's the code which I use for my Android custom cursor adapter which I use to bind data to my list view.
public class MessageAdapter extends CursorAdapter {
private Cursor mCursor;
private Context mContext;
private final LayoutInflater mInflater;
public MessageAdapter(Context context, Cursor c) {
super(context, c);
mInflater=LayoutInflater.from(context);
mContext=context;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView mobileNo=(TextView)view.findViewById(R.id.mobileNolistitem);
mobileNo.setText(cursor.getString(cursor.getColumnIndex(TextMeDBAdapter.KEY_MOBILENO)));
TextView frequency=(TextView)view.findViewById(R.id.frequencylistitem);
frequency.setText(cursor.getString(cursor.getColumnIndex(TextMeDBAdapter.KEY_FREQUENCY)));
TextView rowid=(TextView)view.findViewById(R.id.rowidlistitem);
rowid.setText(cursor.getString(cursor.getColumnIndex(TextMeDBAdapter.KEY_ID)));
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
final View view=mInflater.inflate(R.layout.message_list_item,parent,false);
return view;
}
}
I know that there's another efficient way to do this which reuses the list item instantiated. Can someone tell me how?