AutoCompleteTextView adaptador no se presentan desplegable?
-
30-09-2019 - |
Pregunta
Aquí es mi método onCreate:
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Intent intent = getIntent();
if (intent.getData() == null)
intent.setData(Formulas.CONTENT_URI);
AutoCompleteTextView searchBar = (AutoCompleteTextView)findViewById(R.id.searchBar);
Cursor c = getContentResolver().query(getIntent().getData(),new String[] { Formulas.TITLE }, null, null, null);
SimpleCursorAdapter searchAdapter =
new SimpleCursorAdapter(this, android.R.layout.simple_dropdown_item_1line, c,
new String[] { Formulas.TITLE } , new int[] { android.R.id.text1} );
searchBar.setAdapter(searchAdapter);
}
Lo hice introducir algunos datos de ejemplo en mi databaseopenhelper:
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE formula ( \n" +
"_id INTEGER PRIMARY KEY AUTOINCREMENT, \n" +
"title TEXT NOT NULL, \n" +
"formula TEXT NOT NULL \n" +
");");
db.execSQL("INSERT INTO formula VALUES ( \n" +
"null, \"Pythagorean theorium\", \"a^2+b^2=c^2\" \n" +
"); ");
db.execSQL("INSERT INTO formula VALUES ( \n" +
"null, \"Perimeter of a square\", \"l^2 * w^2\" \n" +
"); ");
db.execSQL("INSERT INTO formula VALUES ( \n" +
"null, \"Area of a square\", \"l^4\" \n" +
"); ");
}
El problema es donde hice el adaptador a la AutoCompleteTextView
, espero que los valores que he insertado utilizando el método SQLiteDatabase.execSQL(String)
. Pero no hay nada allí? El cuadro desplegable ni siquiera aparece? Solía ??depuración y encontré que el Cursor
no era nula y tampoco lo fue el adaptador o AutoCompleteTextView
? ¿Cual podría ser el problema? Ya definí mi propia ContentProvider.
Solución
La consulta devuelve nada porque el URI contenido era defectuosa y completamente mi culpa. Aquí es el hilo relavent.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow