您好我是Android新手。我想将我的数据库链接到自动完成文本视图。我可以看到向下滚动列表,我可以从中选择我的文本。但我用来检索所选文本的getText()方法不起作用。我只得到我在文本框中键入的内容,因此我无法从数据库中检索。请帮助我...给我的代码的片段
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, getAllCountries());
final AutoCompleteTextView input_text = (AutoCompleteTextView)findViewById(R.id.Language);
input_text.setAdapter(adapter);
Linkify.addLinks(input_text, Linkify.ALL);
Button button1=(Button)findViewById(R.id.button1);
final Editable name1=input_text.getText();
.
.
.
public String[] getAllCountries()
{
Cursor cursor = db.rawQuery("SELECT * FROM colors ",null);
if(cursor.getCount() >0)
{
String[] str = new String[cursor.getCount()];
int i = 0;
while (cursor.moveToNext())
{
str[i] = cursor.getString(cursor.getColumnIndex("English"));
i++;
}
return str;
}
else
{
return new String[] {};
}
}
答案 0 :(得分:0)
我正在使用此代码创建列表试试这个:
String reciv ;
ArrayList<String> first = new ArrayList<String>();
cursor = dbm.columnValueofTable();
cursor.moveToFirst();
startManagingCursor(cursor);
for (int i = 0; i < cursor.getCount(); i++) {
reciv = cursor.getString(cursor
.getColumnIndex("row1"));
first.add(reciv);
}
System.out.println("LIST OF COURSE NAME " + first);
final String[] arrayOfStrings;
arrayOfStrings = first.toArray(new String[first.size()]);
AutoCompleteTextView lst = (AutoCompleteTextView ) dialog
.findViewById(R.id.dialog_list);
lst.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,android.R.id.text1,
arrayOfStrings));