2014-10-31 32 views
0

我是新来的android,我正在开发一个应用程序,我必须从服务器获取数据需要存储在sqlite中的数据,所以每次我不应该击中服务器,当我想从数据库中获取,在这个应用程序我使用片段概念,当我在多自动完成文本视图中输入单个字符时,它基于json响应中的名称,它需要显示与该字符在下拉列表中匹配的电子邮件ID。我做了代码没有得到错误,但没有得到预期的结果textview如何显示multiautocomplete textview中的json数据?

当我调试代码下面的代码块没有执行我不知道什么是这个问题,你可以帮我任何一个

new Handler().post(new Runnable() { 

      public void run() { 

       Cursor cursor = contactDataSource.getAllData(); 

       if (BuildConfig.DEBUG) 
        Log.d(TAG, "total contcat count :" + cursor.getCount()); 

       while (cursor.moveToNext()) { 

        if (BuildConfig.DEBUG) 

         Log.d(TAG, 
           "Contact from cursor:" 
             + cursor.getString(cursor 
               .getColumnIndex(ExistingContactTable.COL_NAME))); 

       } 

       customAdapter = new CustomContactAdapter(getActivity(), cursor); 

       Log.i("Custom contact adapter", "" + customAdapter); 


       if (customAdapter != null) 

        editorIdSharableEmail.setAdapter(customAdapter); 

      } 
     }); 

回答

0

首先通过JSON 得到阵列所有数据,然后使用该数组

String[] str={"Andoid","Jelly Bean","Froyo", 
       "Ginger Bread","Eclipse Indigo","Eclipse Juno"}; 

    MultiAutoCompleteTextView mt=(MultiAutoCompleteTextView) 
      findViewById(R.id.multiAutoCompleteTextView1); 

    mt.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer()); 

    ArrayAdapter<String> adp=new ArrayAdapter<String>(this, 
      android.R.layout.simple_dropdown_item_1line,str); 

    mt.setThreshold(1); 
    mt.setAdapter(adp); 

如果你不知道如何从JSON数据,然后检查this并检查this