【问题标题】:autocompletetextview list display from database and onitemclicklister来自数据库和 onitemclicklister 的 autocompletetextview 列表显示
【发布时间】:2012-04-13 09:37:35
【问题描述】:

我想实现一个 onclicklister 来自动完成文本视图,从数据库表中获取结果。
我用谷歌搜索了它,但没有得到我想要的。 stackoverflow link

在我的自动完成文本视图中,我将显示用户的名称,如果您单击所选项目,它应该打开用户详细信息页面,为此我从用户表中获取用户名和 ID,但我必须在自动完成文本视图中仅显示名称该用户 ID 它发送请求并打开用户详细信息屏幕。

提前致谢。

【问题讨论】:

    标签: android listview autocompletetextview android-cursoradapter


    【解决方案1】:

    维护两个数组.. 一个用于用户名,另一个用于 id.. 现在我想您知道如何从数据库中获取任何值...在该 edittext 下方放置一个 edittext 字段和一个 listview.. 结果将是显示在该列表视图中... 现在创建一个线程,它将不断检查edittext中的字符串..就像这样..

       s1="";
      s2=youredittext.getText().toString();
       new Thread(new Runnable() {
              public void run() {
    
              while(bool){
    
                  s2=youredittext.getText().toString();
              if(s1!=s2 && s2.length()>=1){
    
                  s1=s2;
                             //here search the database for the name starting with the string in s1 and get the user name and id fields..and populate the arrays...
                                }
                               runOnUiThread(new Runnable() {
                         public void run() {
                             adapter.clear();<--- this will clear the list every time a new letter is added or removed from the edittext.. and add relevent items..
                             for(int z=0;z<namesarray.length;z++){
    
                                 adapter.add(namesarray[z]);
                             }
                             adapter.notifyDataSetChanged();
    
    
    
                        }
                    });
         }}).start();
    

    当您单击任何项​​目时,会获取该列表中项目的位置.. 并且 ids 数组中该索引处的项目将是相应的 id..

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-30
      • 1970-01-01
      • 2013-10-27
      • 1970-01-01
      • 1970-01-01
      • 2014-04-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多