List of usage examples for android.support.v4.widget SimpleCursorAdapter SimpleCursorAdapter
public SimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags)
From source file:com.tinbytes.simplesearchapp.SimpleListViewActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_simple_list_view); lvAnimals = (ListView) findViewById(R.id.list); scaAnimals = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2, null, new String[] { DatabaseContract.AnimalColumns.NAME, DatabaseContract.AnimalColumns.CATEGORY }, new int[] { android.R.id.text1, android.R.id.text2 }, 0); lvAnimals.setAdapter(scaAnimals);/*from w w w.jav a2s .c o m*/ lvAnimals.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // ListView Clicked item index Cursor c = (Cursor) lvAnimals.getItemAtPosition(position); // Show Alert Toast.makeText(getApplicationContext(), "Position " + position + " - Animal " + c.getString(c.getColumnIndex(DatabaseContract.AnimalColumns.NAME)), Toast.LENGTH_LONG).show(); } }); getSupportLoaderManager().initLoader(ANIMAL_LOADER, null, this); handleIntent(getIntent()); }
From source file:com.tinbytes.simplelistviewapp.SimpleListViewActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_simple_list_view); lvAnimals = (ListView) findViewById(R.id.list); scaAnimals = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2, null, new String[] { DatabaseContract.AnimalColumns.NAME, DatabaseContract.AnimalColumns.CATEGORY }, new int[] { android.R.id.text1, android.R.id.text2 }, 0); lvAnimals.setAdapter(scaAnimals);//from w ww .j a v a 2 s. com lvAnimals.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // ListView Clicked item index Cursor c = (Cursor) lvAnimals.getItemAtPosition(position); // Show Alert Toast.makeText(getApplicationContext(), "Position " + position + " - Animal " + c.getString(c.getColumnIndex(DatabaseContract.AnimalColumns.NAME)), Toast.LENGTH_LONG).show(); } }); getSupportLoaderManager().initLoader(ANIMAL_LOADER, null, this); }
From source file:org.uab.deic.uabdroid.solutions.unit4.AppListActivity.java
@Override public void onCreate(Bundle _savedInstanceState) { super.onCreate(_savedInstanceState); setContentView(R.layout.listactivity); // The adapter is created without a cursor (third parameter is null) mCursorAdapter = new SimpleCursorAdapter(getBaseContext(), R.layout.results_list_item, null, COLUMNS_FROM, VIEWS_TO, 0);/*w ww . j ava 2s . c o m*/ // Set the listView adapter to the one we have just created ListView listView = (ListView) findViewById(R.id.list_view); listView.setAdapter(mCursorAdapter); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> _parentView, View _view, int _position, long _id) { Intent intent = new Intent(getBaseContext(), ResultsActivity.class); intent.putExtra(DatabaseAdapter.KEY_ID, _id); startActivity(intent); } }); // We call the LoaderManager with a new instance of an object that implements the LoaderCallbacks // interface, which is defined below getSupportLoaderManager().initLoader(0, null, new DatabaseCursorLoaderCallback()); }
From source file:com.tencent.wcdb.sample.encryptdb.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mListView = (ListView) findViewById(R.id.list); mAdapter = new SimpleCursorAdapter(this, R.layout.main_listitem, null, new String[] { "content", "_id", "sender" }, new int[] { R.id.list_tv_content, R.id.list_tv_id, R.id.list_tv_sender }, 0); mListView.setAdapter(mAdapter);//from w w w . j a va 2 s . co m findViewById(R.id.btn_init_plain).setOnClickListener(new View.OnClickListener() { // Init plain-text button pressed. // Create or open database in version 1, then refresh adapter. @Override public void onClick(View v) { new AsyncTask<Void, Void, Cursor>() { @Override protected void onPreExecute() { mAdapter.changeCursor(null); } @Override protected Cursor doInBackground(Void... params) { if (mDBHelper != null && mDB != null && mDB.isOpen()) { mDBHelper.close(); mDBHelper = null; mDB = null; } mDBHelper = new PlainTextDBHelper(MainActivity.this); mDBHelper.setWriteAheadLoggingEnabled(true); mDB = mDBHelper.getWritableDatabase(); mDBVersion = mDB.getVersion(); return mDB.rawQuery("SELECT rowid as _id, content, '???' as sender FROM message;", null); } @Override protected void onPostExecute(Cursor cursor) { mAdapter.changeCursor(cursor); } }.execute(); } }); findViewById(R.id.btn_init_encrypted).setOnClickListener(new View.OnClickListener() { // Init encrypted button pressed. // Create or open database in version 2, then refresh adapter. // If plain-text database exists and encrypted one does not, transfer all // data from the plain-text database (which in version 1), then upgrade it // to version 2. // See EncryptedDBHelper.java for details about data transfer and schema upgrade. @Override public void onClick(View v) { new AsyncTask<Void, Void, Cursor>() { @Override protected void onPreExecute() { mAdapter.changeCursor(null); } @Override protected Cursor doInBackground(Void... params) { if (mDBHelper != null && mDB != null && mDB.isOpen()) { mDBHelper.close(); mDBHelper = null; mDB = null; } String passphrase = "passphrase"; mDBHelper = new EncryptedDBHelper(MainActivity.this, passphrase); mDBHelper.setWriteAheadLoggingEnabled(true); mDB = mDBHelper.getWritableDatabase(); mDBVersion = mDB.getVersion(); return mDB.rawQuery("SELECT rowid as _id, content, sender FROM message;", null); } @Override protected void onPostExecute(Cursor cursor) { mAdapter.changeCursor(cursor); } }.execute(); } }); findViewById(R.id.btn_insert).setOnClickListener(new View.OnClickListener() { // Insert button pressed. // Insert a message to the database. // To test data transfer, init plain-text database, insert messages, // then init encrypted database. final DateFormat DATE_FORMAT = SimpleDateFormat.getDateTimeInstance(); @Override public void onClick(View v) { new AsyncTask<Void, Void, Cursor>() { @Override protected void onPreExecute() { mAdapter.changeCursor(null); } @Override protected Cursor doInBackground(Void... params) { if (mDB == null || !mDB.isOpen()) return null; String message = "Message inserted on " + DATE_FORMAT.format(new Date()); if (mDBVersion == 1) { mDB.execSQL("INSERT INTO message VALUES (?);", new Object[] { message }); return mDB.rawQuery("SELECT rowid as _id, content, '???' as sender FROM message;", null); } else { mDB.execSQL("INSERT INTO message VALUES (?, ?);", new Object[] { message, "Me" }); return mDB.rawQuery("SELECT rowid as _id, content, sender FROM message;", null); } } @Override protected void onPostExecute(Cursor cursor) { if (cursor == null) return; mAdapter.changeCursor(cursor); } }.execute(); } }); }
From source file:MainActivity.java
private void updateWordList() { SimpleCursorAdapter simpleCursorAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, mDB.getWordList(), new String[] { "word" }, new int[] { android.R.id.text1 }, 0); mListView.setAdapter(simpleCursorAdapter); }
From source file:com.gerolab.sdksample.StepsLogActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_log); mLoadingView = findViewById(R.id.loading); mTotalTextView = (TextView) findViewById(R.id.text_total); ListView listView = (ListView) findViewById(R.id.list); mAdapter = new SimpleCursorAdapter(this, R.layout.simple_list_item, null, new String[] { TableSteps.COLUMN_ID, TableSteps.COLUMN_STEPS, TableSteps.COLUMN_CALORIES, TableSteps.COLUMN_DISTANCE }, new int[] { R.id.text1, R.id.text2, R.id.text3, R.id.text4 }, 0); listView.setAdapter(mAdapter);// w w w .j a v a2s . c o m mLoadingView.setVisibility(View.VISIBLE); // init loader getSupportLoaderManager().initLoader(LOADER_ID_STEPS, null, this); // load complex data from DB new TotalStepsLoadTask().execute(); }
From source file:org.sufficientlysecure.keychain.ui.widget.CacheTTLSpinner.java
private void initView(Context context) { CacheTTLPrefs prefs = Preferences.getPreferences(context).getPassphraseCacheTtl(); MatrixCursor cursor = new MatrixCursor(new String[] { "_id", "TTL", "description" }, 5); int i = 0;// w w w.java 2 s . co m for (int ttl : CacheTTLPrefs.CACHE_TTLS) { if (!prefs.ttlTimes.contains(ttl)) { continue; } cursor.addRow( new Object[] { i++, ttl, getContext().getString(CacheTTLPrefs.CACHE_TTL_NAMES.get(ttl)) }); } setAdapter(new SimpleCursorAdapter(getContext(), R.layout.simple_item, cursor, new String[] { "description" }, new int[] { R.id.simple_item_text }, 0)); }
From source file:com.mfcoding.locationBP.UI.fragments.LocationListFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); activity = (LocationActivity) getActivity(); // Create a new SimpleCursorAdapter that displays the name of each nearby // venue and the current distance to it. adapter = new SimpleCursorAdapter(activity, android.R.layout.two_line_list_item, cursor, new String[] { LocationsContentProvider.KEY_LOCATION_LAT, LocationsContentProvider.KEY_LOCATION_LNG }, new int[] { android.R.id.text1, android.R.id.text2 }, 0); // Allocate the adapter to the List displayed within this fragment. setListAdapter(adapter);//from w ww .j a v a 2 s . c om // Populate the adapter / list using a Cursor Loader. getLoaderManager().initLoader(0, null, this); }
From source file:net.potterpcs.recipebook.TagSearchDialog.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.tagsearch, container, false); RecipeBook app = (RecipeBook) getActivity().getApplication(); Cursor cursor = app.getData().getAllTags(); GridView grid = (GridView) v.findViewById(R.id.tagsearchgrid); clicked = null;/*from w ww.j a v a 2 s .com*/ adapter = new SimpleCursorAdapter(getActivity(), android.R.layout.simple_list_item_1, cursor, new String[] { RecipeData.TT_TAG }, new int[] { android.R.id.text1 }, 0); grid.setAdapter(adapter); grid.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { RecipeBookActivity activity = (RecipeBookActivity) getActivity(); Intent intent = new Intent(activity, RecipeBookActivity.class); if (activity.isSearchMode()) { intent.putExtra(RecipeBook.SEARCH_EXTRA, activity.getSearchQuery()); } if (activity.isTimeSearch()) { intent.putExtra(RecipeBook.TIME_EXTRA, true); intent.putExtra(RecipeBook.TIME_EXTRA_MIN, activity.getMinTime()); intent.putExtra(RecipeBook.TIME_EXTRA_MAX, activity.getMaxTime()); } intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); adapter.getCursor().moveToPosition(position); intent.putExtra(RecipeBook.TAG_EXTRA, adapter.getCursor().getString(adapter.getCursor().getColumnIndex(RecipeData.TT_TAG))); startActivity(intent); dismiss(); } }); return v; }
From source file:com.android.transmart.UI.fragments.PlaceListFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); activity = (PlaceActivity) getActivity(); // Create a new SimpleCursorAdapter that displays the name of each nearby // venue and the current distance to it. adapter = new SimpleCursorAdapter(activity, android.R.layout.two_line_list_item, cursor, new String[] { PlacesContentProvider.KEY_NAME, PlacesContentProvider.KEY_DISTANCE }, new int[] { android.R.id.text1, android.R.id.text2 }, 0); // Allocate the adapter to the List displayed within this fragment. setListAdapter(adapter);/* ww w. j a v a 2s. c om*/ // Populate the adapter / list using a Cursor Loader. getLoaderManager().initLoader(0, null, this); }