将 SQLite 链接到 Android 中的自动完成 TextView?
你好,我是 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[] {};
}
}
Hello i am new to Android. I wanted to link my database to auto complete text view. I can see the scroll down list and i am able to select my text from that. but the getText() method i used to retrieve the selected text is not working. I am getting only what i typed in the text box and so i am not able to retrieve from database.please help me..snippet of my code given
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[] {};
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我正在使用此代码来创建列表尝试以下操作:
I am using this code to create list try this: