【发布时间】:2020-12-05 05:47:13
【问题描述】:
请我的 Android 应用程序在任何 Android 应用程序版本中都能正常工作,但在 android 9.0 上不能工作??在模拟器上从android studio运行代码时没有显示错误,问题是AutoCompleteTextView不起作用,但在其他更高和更低版本上运行良好。我的代码是:
AutoCompleteTextView srch_txt=(AutoCompleteTextView) findViewById(R.id.srch_txt);
DBConnection db = new DBConnection(this);
//SQLiteDatabase dbb = db.getWritableDatabase();//connect to MyDB
SQLiteDatabase dbb = db.getReadableDatabase();//connect to MyDB
final String [] mydata;
//Inside the method you've read the cursor, loop through it and add those item to array
String sql="SELECT * FROM revuesC";
//execute SQL
Cursor cr= dbb.rawQuery(sql, null);
mydata = new String[cr.getCount()];//create array string based on numbers of row
int i=0;
while (cr.moveToNext()) {
mydata[i]= cr.getString(1);
i++;
}
cr.moveToFirst();
ArrayAdapter<String> adapter = new ArrayAdapter<String>
(this,android.R.layout.select_dialog_item,mydata);
//Getting the instance of AutoCompleteTextView
//AutoCompleteTextView actv = (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView);
srch_txt.setThreshold(1);//will start working from first character
srch_txt.setAdapter(adapter);//setting the adapter data into the AutoCompleteTextView
cr.close();
> Blockquote
【问题讨论】:
标签: android sqlite autocompletetextview dbconnection