Android SimpleCursorAdapter - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android SimpleCursorAdapter class.

This code example shows how to use the following methods:setDropDownViewResource
    Cursor c=a.managedQuery(Contacts.Phones.CONTENT_URI,
                            PROJECTION,
                            Contacts.Phones.TYPE+"=?", ARGS,
                            Contacts.Phones.NAME);
     
    SimpleCursorAdapter adapter=new SimpleCursorAdapter(a,
                                    android.R.layout.simple_spinner_item,
                                    c,
                                    new String[] {
                                      Contacts.Phones.NAME
                                    }, 
                                    new int[] { 
                                      android.R.id.text1
                                    }); 
                                     
    adapter.setDropDownViewResource(
            android.R.layout.simple_spinner_dropdown_item);
     
    return(adapter);
  } 
} 
7
CodeRank
This code example shows how to use the following methods:setDropDownViewResource
    String[] ARGS={String.valueOf(Phone.TYPE_MOBILE)};
    Cursor c=a.managedQuery(Phone.CONTENT_URI,
                            PROJECTION, Phone.TYPE+"=?",
                            ARGS, Contacts.DISPLAY_NAME);
     
    SimpleCursorAdapter adapter=new SimpleCursorAdapter(a,
                                    android.R.layout.simple_spinner_item,
                                    c,
                                    new String[] {
                                      Contacts.DISPLAY_NAME
                                    }, 
                                    new int[] { 
                                      android.R.id.text1
                                    }); 
                                     
    adapter.setDropDownViewResource(
            android.R.layout.simple_spinner_dropdown_item);
     
    return(adapter);
  } 
} 
7
CodeRank
This code example shows how to use the following methods:setAdapter
		super.onCreate(savedInstanceState);
 
		db = new MyDatabase(this);
		employees = db.getEmployees(); // you would not typically call this on the main thread
 
		ListAdapter adapter = new SimpleCursorAdapter(this, 
				android.R.layout.simple_list_item_1, 
				employees, 
				new String[] {"FirstName"}, 
				new int[] {android.R.id.text1});
 
		getListView().setAdapter(adapter);
	} 
 
	@Override 
	protected void onDestroy() { 
		super.onDestroy(); 
		employees.close();
		db.close();
	} 
8
CodeRank
This code example shows how to use the following methods:swapCursor
  public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    adapter.swapCursor(cursor);
  } 
 
  public void onLoaderReset(Loader<Cursor> loader) {
    adapter.swapCursor(null);
  } 
 
  @Override 
  public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
    long time=0;
    String formattedTime=null;
 
    switch (columnIndex) {
      case 2: 
        time=cursor.getLong(columnIndex);
        formattedTime=
            DateUtils.formatDateTime(this, time,
                                     DateUtils.FORMAT_ABBREV_RELATIVE);
        ((TextView)view).setText(formattedTime);
7
CodeRank
This code example shows how to use the following methods:
                                        Contacts.DISPLAY_NAME,
                                      }; 
    Cursor c=a.managedQuery(Contacts.CONTENT_URI,
                            PROJECTION, null, null, null);
     
    return(new SimpleCursorAdapter( a,
                                    android.R.layout.simple_list_item_1,
                                    c,
                                    new String[] {
                                      Contacts.DISPLAY_NAME
                                    }, 
                                    new int[] { 
                                      android.R.id.text1
                                    })); 
  } 
   
  ListAdapter buildPhonesAdapter(Activity a) {
    String[] PROJECTION=new String[] {  Contacts._ID,
                                        Contacts.DISPLAY_NAME,
                                        Phone.NUMBER
7
CodeRank
This code example shows how to use the following methods:swapCursor
  public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    adapter.swapCursor(cursor);
  } 
 
  public void onLoaderReset(Loader<Cursor> loader) {
    adapter.swapCursor(null);
  } 
 
  @Override 
  public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
    long time=0;
    String formattedTime=null;
 
    switch (columnIndex) {
      case 2: 
      case 3: 
        time=cursor.getLong(columnIndex);
        formattedTime=
            DateUtils.formatDateTime(this, time,
                                     DateUtils.FORMAT_ABBREV_RELATIVE);
7
CodeRank
This code example shows how to use the following methods:setViewBinder
        Cursor c = getContentResolver().query(Phone.CONTENT_URI,
                PHONE_PROJECTION, null, null, null);
        startManagingCursor(c);
 
        // Map Cursor columns to views defined in simple_list_item_2.xml 
        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
                android.R.layout.simple_list_item_2, c,
                        new String[] {
                            Phone.TYPE,
                            Phone.NUMBER
                        }, 
                        new int[] { android.R.id.text1, android.R.id.text2 });
        //Used to display a readable string for the phone type 
        adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
            public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
                //Let the adapter handle the binding if the column is not TYPE 
                if (columnIndex != COLUMN_TYPE) {
                    return false; 
                } 
                int type = cursor.getInt(COLUMN_TYPE);
7
CodeRank
This code example shows how to use the following methods:setDropDownViewResource
    String[] ARGS={String.valueOf(Phone.TYPE_MOBILE)};
    Cursor c=a.managedQuery(Phone.CONTENT_URI,
                            PROJECTION, Phone.TYPE+"=?",
                            ARGS, Contacts.DISPLAY_NAME);
     
    SimpleCursorAdapter adapter=new SimpleCursorAdapter(a,
                                    android.R.layout.simple_spinner_item,
                                    c,
                                    new String[] {
                                      Contacts.DISPLAY_NAME
                                    }, 
                                    new int[] { 
                                      android.R.id.text1
                                    }); 
                                     
    adapter.setDropDownViewResource(
            android.R.layout.simple_spinner_dropdown_item);
     
    return(adapter);
  } 
} 
7
CodeRank
This code example shows how to use the following methods:
                                      }; 
    Cursor c=a.managedQuery(Contacts.People.CONTENT_URI,
                            PROJECTION, null, null,
                            Contacts.People.DEFAULT_SORT_ORDER);
     
    return(new SimpleCursorAdapter( a,
                                    android.R.layout.simple_list_item_1,
                                    c,
                                    new String[] {
                                      Contacts.PeopleColumns.NAME
                                    }, 
                                    new int[] { 
                                      android.R.id.text1
                                    })); 
  } 
   
  ListAdapter buildPhonesAdapter(Activity a) {
    String[] PROJECTION=new String[] {  Contacts.Phones._ID,
                                        Contacts.Phones.NAME,
                                        Contacts.Phones.NUMBER
7
CodeRank
This code example shows how to use the following methods:setDropDownViewResource
    Cursor c=a.managedQuery(Contacts.Phones.CONTENT_URI,
                            PROJECTION,
                            Contacts.Phones.TYPE+"=?", ARGS,
                            Contacts.Phones.NAME);
     
    SimpleCursorAdapter adapter=new SimpleCursorAdapter(a,
                                    android.R.layout.simple_spinner_item,
                                    c,
                                    new String[] {
                                      Contacts.Phones.NAME
                                    }, 
                                    new int[] { 
                                      android.R.id.text1
                                    }); 
                                     
    adapter.setDropDownViewResource(
            android.R.layout.simple_spinner_dropdown_item);
     
    return(adapter);
  } 
} 
7
CodeRank

Related Android SimpleCursorAdapter Questions & Answers:

Other Android SimpleCursorAdapter Examples

17:	    // now create a new list adapter bound to the cursor.
18:	    // SimpleListAdapter is designed for binding to a Cursor.
19:	    ListAdapter adapter = new SimpleCursorAdapter(this, // Context.
20:	        android.R.layout.two_line_list_item, // Specify the row template
21:	                            // to use (here, two

Read More

3:	
4:	    // This is the Adapter being used to display the list's data
5:	    SimpleCursorAdapter mAdapter;
6:	
7:	    // These are the Contacts rows that we will retrieve
-
35:	        // Create an empty adapter we will use to display the loaded data.
36:	        // We pass null for the cursor, then update it in onLoadFinished()
37:	        mAdapter = new SimpleCursorAdapter(this, 
38:	                android.R.layout.simple_list_item_1, null,
39:	                fromColumns, toViews, 0);

Read More

See Code Examples for Android SimpleCursorAdapter Methods: