private void setAdapter(Cursor cursor) { if (mLv.getAdapter() == null) { SimpleCursorAdapter adapter = new SimpleCursorAdapter(SearchViewActivity2.this, R.layout.item_layout, cursor, new String[]{"name"}, new int[]{R.id.text1}); mLv.setAdapter(adapter); } else { ((SimpleCursorAdapter) mLv.getAdapter()).changeCursor(cursor); } } }
@Override public void onLoaderReset(android.support.v4.content.Loader<Cursor> loader) { mAdapter.swapCursor(null); } }
/** * Standard constructor. * * @param context The context where the ListView associated with this * SimpleListItemFactory is running * @param layout resource identifier of a layout file that defines the views * for this list item. The layout file should include at least * those named views defined in "to" * @param c The database cursor. Can be null if the cursor is not available yet. * @param from A list of column names representing the data to bind to the UI. Can be null * if the cursor is not available yet. * @param to The views that should display column in the "from" parameter. * These should all be TextViews. The first N views in this list * are given the values of the first N columns in the from * parameter. Can be null if the cursor is not available yet. * @param flags Flags used to determine the behavior of the adapter, * as per {@link CursorAdapter#CursorAdapter(Context, Cursor, int)}. */ public SimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) { super(context, layout, c, flags); mTo = to; mOriginalFrom = from; findColumns(from); }
private void initEvent() { mMySQLite = new MySQLite(this); mDbReader = mMySQLite.getReadableDatabase(); mSimpleCursorAdapter = new SimpleCursorAdapter(MyListActivity.this, R.layout.listview_sql_item, null, new String[] { MySQLite.KEY_logOutput, MySQLite.KEY_timestamp }, new int[] { R.id.logoutput, R.id.timestamp }, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); mListView.setAdapter(mSimpleCursorAdapter); refresh(); }
String[] from = {DbContract.CategoryEntry.COLUMN_NAME}; int[] to = {R.id.text1}; adapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.simple_spinner_item, c, from, to, CursorAdapter.FLAG_AUTO_REQUERY); adapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { for (int i = 0; i < adapter.getCount(); i++){ c.moveToPosition(i); if (c.getInt(c.getColumnIndexOrThrow(DbContract.CategoryEntry.COLUMN_ID)) == currentCat) {
private void initAutoComplete() { mHistory.open(); String[] from = new String[] { HistoryOpenHelper.COLUMN_REALM }; int[] to = new int[] { android.R.id.text1 }; SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_dropdown_item_1line, null, from, to, 0); // Set the CursorToStringConverter, to provide the labels for the // choices to be displayed in the AutoCompleteTextView. adapter.setCursorToStringConverter(new CursorToStringConverter() { public String convertToString(android.database.Cursor cursor) { final int columnIndex = cursor .getColumnIndexOrThrow(HistoryOpenHelper.COLUMN_REALM); return cursor.getString(columnIndex); } }); // Set the FilterQueryProvider, to run queries for choices // that match the specified input. adapter.setFilterQueryProvider(new FilterQueryProvider() { public Cursor runQuery(CharSequence constraint) { String partialInput = (constraint != null ? constraint .toString() : ""); return mHistory.getHistoryCursor(partialInput); } }); mSiteAddress.setAdapter(adapter); }
streamActv.setOnFocusChangeListener(focusChangeListener); SimpleCursorAdapter combinedAdapter = new SimpleCursorAdapter( that, R.layout.emoji_tile, null, new String[]{Emoji.NAME_FIELD, Emoji.NAME_FIELD}, new int[]{R.id.emojiImageView, R.id.nameTV}, 0); combinedAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Cursor cursor, int columnIndex) { combinedAdapter.setCursorToStringConverter(new SimpleCursorAdapter.CursorToStringConverter() { @Override public CharSequence convertToString(Cursor cursor) { combinedAdapter.setFilterQueryProvider(new FilterQueryProvider() { @Override public Cursor runQuery(CharSequence charSequence) {
}; mAdapter = new SimpleCursorAdapter(getActivity().getBaseContext(), R.layout.sessionlistfragment, null, from, to, 0); mAdapter.setViewBinder(new SessionViewBinder());
@Override protected void onPostExecute(Cursor result) { this.adapter.changeCursor(result); }
@Override protected void onResume() { super.onResume(); if (mAdapter.getCount() == 0) { String permissao = Manifest.permission.READ_EXTERNAL_STORAGE; if (ActivityCompat.checkSelfPermission(this, permissao) == PackageManager.PERMISSION_GRANTED) { getSupportLoaderManager().initLoader(0, null, this); } else { ActivityCompat.requestPermissions(this, new String[]{permissao}, 0); } } Intent it = new Intent(this, Mp3ServiceImpl.class); startService(it); bindService(it, this, 0); } @Override
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); String[] columns = new String[]{ SampleContentProvider.Person.AGE, SampleContentProvider.Person.NAME}; int[] ids = { R.id.person_age, R.id.person_name}; adapter = new SimpleCursorAdapter(this, R.layout.person_item, null, columns, ids, 0); ((ListView) findViewById(R.id.list_view)).setAdapter(adapter); findViewById(R.id.add).setOnClickListener(this); findViewById(R.id.delete).setOnClickListener(this); getSupportLoaderManager().initLoader(0, null, this); }
String[] from = {DbContract.CategoryEntry.COLUMN_NAME}; int[] to = {R.id.text1}; adapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.simple_spinner_item, c, from, to, CursorAdapter.FLAG_AUTO_REQUERY); adapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { for (int i = 0; i < adapter.getCount(); i++){ c.moveToPosition(i); if (c.getInt(c.getColumnIndexOrThrow(DbContract.CategoryEntry.COLUMN_ID)) == currentCat) {
streamActvAdapter = new SimpleCursorAdapter( that, R.layout.stream_tile, null, new String[]{Stream.NAME_FIELD}, new int[]{R.id.name}, 0); streamActvAdapter.setCursorToStringConverter(new SimpleCursorAdapter.CursorToStringConverter() { @Override public CharSequence convertToString(Cursor cursor) { streamActvAdapter.setFilterQueryProvider(new FilterQueryProvider() { @Override public Cursor runQuery(CharSequence charSequence) { subjectActvAdapter = new SimpleCursorAdapter( that, R.layout.stream_tile, null, new String[]{Message.SUBJECT_FIELD}, new int[]{R.id.name}, 0); subjectActvAdapter.setCursorToStringConverter(new SimpleCursorAdapter.CursorToStringConverter() { @Override public CharSequence convertToString(Cursor cursor) { subjectActvAdapter.setFilterQueryProvider(new FilterQueryProvider() { @Override public Cursor runQuery(CharSequence charSequence) { emailActvAdapter = new SimpleCursorAdapter( that, R.layout.stream_tile, null, new String[]{Person.EMAIL_FIELD}, new int[]{R.id.name}, 0); emailActvAdapter
private void refresh() { Cursor mCursor = mDbReader.query(MySQLite.DB_NAME, null, null, null, null, null, "_id desc"); mSimpleCursorAdapter.changeCursor(mCursor); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_lista_contatos); final ListView listView = (ListView) findViewById(br.com.livroandroid.contatos.R.id.listView); listView.setOnItemClickListener(this); // Lista os contatos Uri contatos = ContactsContract.Contacts.CONTENT_URI; Cursor cursor = getContentResolver().query(contatos, null, ContactsContract.Contacts.HAS_PHONE_NUMBER +" = 1 ", null, ContactsContract.Contacts.DISPLAY_NAME); // Não temos como jogar a foto aqui SimpleCursorAdapter adapter = new SimpleCursorAdapter( getBaseContext(), R.layout.adapter_contato, cursor, new String[]{ContactsContract.Contacts.DISPLAY_NAME}, new int[]{R.id.tNome}, 0); listView.setAdapter(adapter); Toast.makeText(this, "Com o SimpleCursorAdapter diretamente não conseguimos mostrar a foto.", Toast.LENGTH_SHORT).show(); }
String[] from = {DbContract.CategoryEntry.COLUMN_NAME}; int[] to = {R.id.text1}; adapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.simple_spinner_item, c, from, to, CursorAdapter.FLAG_AUTO_REQUERY); adapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { for (int i = 0; i < adapter.getCount(); i++){ c.moveToPosition(i); if (c.getInt(c.getColumnIndexOrThrow(DbContract.CategoryEntry.COLUMN_ID)) == currentCat) {
@Override public final void onLoadFinished(final Loader<Cursor> arg0, final Cursor cursor) { mAdapter.swapCursor(cursor); mAdapterUpdatePending = false; }
@Override protected void onResume() { super.onResume(); sound.setInactive(false); sound.resume(); datasource.open(); Cursor cursor = datasource.getCursor(); adapter.changeCursor(cursor); if(!GameState.isFinished()) { ((Button)findViewById(R.id.resumeButton)).setEnabled(true); ((Button)findViewById(R.id.resumeButton)).setTextColor(getResources().getColor(R.color.square_error)); } else { ((Button)findViewById(R.id.resumeButton)).setEnabled(false); ((Button)findViewById(R.id.resumeButton)).setTextColor(getResources().getColor(R.color.holo_grey)); } };
/** * Standard constructor. * * @param context The context where the ListView associated with this * SimpleListItemFactory is running * @param layout resource identifier of a layout file that defines the views * for this list item. The layout file should include at least * those named views defined in "to" * @param c The database cursor. Can be null if the cursor is not available yet. * @param from A list of column names representing the data to bind to the UI. Can be null * if the cursor is not available yet. * @param to The views that should display column in the "from" parameter. * These should all be TextViews. The first N views in this list * are given the values of the first N columns in the from * parameter. Can be null if the cursor is not available yet. * @param flags Flags used to determine the behavior of the adapter, * as per {@link CursorAdapter#CursorAdapter(Context, Cursor, int)}. */ public SimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) { super(context, layout, c, flags); mTo = to; mOriginalFrom = from; findColumns(from); }
/** * Creates a cursor adapter given a {@link List<SearchResult>}. * https://stackoverflow.com/questions/11628172/converting-an-arrayadapter-to-cursoradapter-for-use-in-a-searchview/11628527#11628527 * * @param results the results to be placed in the adapter. * @return the adapter. */ public static CursorAdapter getCursorAdapter(Context context, List<SearchResult> results) { int id = 0; MatrixCursor cursor = new MatrixCursor(columnNames); for (SearchResult item : results) { String[] temp = new String[2]; temp[0] = String.valueOf(id); // "_id" temp[1] = item.getPageName(); // "title" cursor.addRow(temp); id++; } return new SimpleCursorAdapter( context, R.layout.search_suggestions_list_item, cursor, from, to, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER ); } }