-1

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.

prasad.gai
  • 2,977
  • 10
  • 58
  • 93
  • -1 without CustomeSimpleCursorAdapter definition we can only guess how to do it ... my first guess is .. you didn't provide proper constructor for CustomeSimpleCursorAdapter ... – Selvin Mar 02 '12 at 10:00
  • hey see some one given proper answer.y did u give down? – prasad.gai Mar 02 '12 at 10:08

1 Answers1

1

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;
    }
}
Hanon
  • 3,917
  • 2
  • 25
  • 29