tags:

views:

27

answers:

0

Hello, i have a custom CursorAdapter that populates a list view from a database. my problem is that the list view never shows the last entry i made in the database. it always shows the one before the last and for some reason when i scroll down the list, the first entry i made to the database, is always the last entry too. i don't know if its just the emulator or something else. please here is the main code for the customised CursorAdapter. thank you

private void fillData() {

        Cursor c = adapter.retrieveItems();
         startManagingCursor(c);

String[] from = new String[]{DBAdapter.NAME, DBAdapter.START_DATE, DBAdapter.START_TIME};
int[] to = new int[]{R.id.viewNameId, R.id.viewDateId, R.id.viewTimeId, };

  customCursorAdapter items = new customCursorAdapter(this, R.layout.view_items, c,from,         to);
 setListAdapter(items);             
    }

    public class customCursorAdapter extends SimpleCursorAdapter {

        private int layout;
        Context context;

public customCursorAdapter(Context context, int layout, Cursor c, String[]from, int[] to) {

                        super(context, layout, c, from, to);
            this.layout = layout;
            this.context = context; 
        }

        @Override
        public void bindView(View view, Context context, Cursor c) {

            int namecol = c.getColumnIndex(DBAdapter.NAME); 
            String name = c.getString(namecol);

            TextView viewItemName = (TextView)findViewById(R.id.viewNameId);
            if(viewItemName != null){
            viewItemName.setText(name);
            viewItemName.setTextColor(Color.RED);
            }
        }


    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
          LayoutInflater inflater = LayoutInflater.from(context);
        final View view = inflater.inflate(layout, parent, false);
            return view;
        }
    }