0 Replies - 743 Views - Last Post: 27 August 2010 - 11:04 AM

#1 irobot  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 41
  • Joined: 02-August 09

problems with listView in custom CursorAdapter

Posted 27 August 2010 - 11:04 AM

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 the emulator or something else. Please here is the main code for the customised CursorAdapter.

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;
		}
	}



Is This A Good Question/Topic? 0
  • +

Page 1 of 1