autocompletetextview列表显示来自数据库和onitemclicklister

时间:2012-04-13 09:37:35

标签: android listview autocompletetextview android-cursoradapter

我想实现一个onclicklister到autocompletetextview,其中包含数据库表的结果。
我用谷歌搜索了它,但没有得到我想要的东西。 stackoverflow link

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

提前致谢。

1 个答案:

答案 0 :(得分:1)

维护两个数组..一个用于用户名,另一个用于id ..现在我想你知道如何从数据库获取任何值...在编辑文本下面放置一个edittext字段和一个列表视图。结果将是显示在该列表视图中... 现在创建一个线程,它将不断检查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 ..

相关问题