I have implemented an application to get the data from local mobile SQLite db and try for send to Custome Simple Cursor adapter class.I am recieving the data from BroadCast Reciever It is used for get the latest record from DB.If use SimpleCursorAdapter then i can get the data from Sqlite DB and updating to UI.But I can't pass the DB content to CustomeSimpleCursorAdapter.So how can i pass db content to CustomeSimpleCursorAdapter?
I have implemented code as follows:
private BroadcastReceiver myReceiver = new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent) {
msh = new MySqliteHelper(GetMsgsScreen.this);
msh.openToWrite();
lst = ((ListView)findViewById(R.id.listView1));
cursor = msh.queueAll();
getFromDB = new String[]{MySqliteHelper.USER_NAME,MySqliteHelper.USER_MESSAGE};
toView = new int[]{R.id.usrName,R.id.msgText};
cursor.moveToFirst();
lst.setAdapter(new SimpleCursorAdapter(GetMsgsScreen.this, R.layout.test, cursor, getFromDB, toView));
updateList();
}
};
Similarly,
If I use CustomeSimpleCursorAdapter instead of SimpleCursorAdapter then how can i display MySqliteHelper.USER_NAME and MySqliteHelper.USER_MESSAGE content to list? please any body help me.
If you want to create a custom adapter subclass of CursorAdapter, you have to override bindView
and newView
method.
public class CustomCursorAdapter extends CursorAdapter {
public CustomCursorAdapter(Context context, Cursor c) {
super(context, c);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView username = (TextView)view.findViewById(R.id.username);
username.setText(cursor.getString(
cursor.getColumnIndex(MySqliteHelper.USER_NAME)));
// Set up other view here
// ...
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(context);
View v = inflater.inflate(R.layout.listItem, parent, false);
bindView(v, context, cursor);
return v;
}
}