AutoCompleteTextView adattatore non visualizzazione discesa?
-
30-09-2019 - |
Domanda
Ecco il mio metodo 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);
}
Ho fatto ingresso alcuni dati di esempio nella mia 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" +
"); ");
}
Il problema è dove ho impostato l'adattatore al AutoCompleteTextView
, mi aspetto che i valori che ho inserito utilizzando il metodo SQLiteDatabase.execSQL(String)
. Ma non c'è nulla? La casella a discesa non ha nemmeno presentarsi? Ho usato il debug e ha scoperto che il Cursor
non era nulla e né era l'adattatore o AutoCompleteTextView
? Quale potrebbe essere il problema? Ho già definito la mia ContentProvider.
Soluzione
La query ha restituito nulla, perché l'URI contenuto era difettoso e completamente colpa mia. Qui è il filo relavent.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow