将 SQLite 链接到 Android 中的自动完成 TextView?

发布于 2025-01-08 08:17:18 字数 1125 浏览 3 评论 0原文

你好,我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白馒头 2025-01-15 08:17:18

我正在使用此代码来创建列表尝试以下操作:

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));

I am using this code to create list try this:

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));
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文