2012-03-05 160 views
-1
ContentResolver cr = getContentResolver();   
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); 
if (cur.getCount() > 0) {  
    while (cur.moveToNext()) { 
    String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID)); 
    String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); 
      c_Name.add(name); 
    } 
} 
name_Val = (String[]) c_Name.toArray(new String[c_Name.size()]); 
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,name_Val); 
txtPhoneName.setAdapter(adapter); 

正如我調試我跟隨的代碼,直到txtPhoneName.setAdapter(adapter)ArrayAdapter adapter充滿接觸開始{null, "Name1", "Name2"...}問題與填充autocompletetextview

當談到autocompletetextView它不顯示任何內容,如果不是我使用固定的String [] d={"NAME1","Name2","name3"}它綁定他們就好了。

+1

嗨,託尼,我改進了你的問題和你提供的代碼。請花更多時間在下次格式化和描述! – WarrenFaith 2012-03-05 15:14:10

回答

0

比它必須爲null,更改此,它應該工作,之前c_Name.add(名稱); 檢查名稱是否爲空!

0

您發佈的代碼無法工作,或者至少您沒有發佈相關內容。

name_Val從來沒有在任何地方使用。此外,請確保您的聯繫人不以null條目開頭,因爲它可能導致不顯示任何內容...

+0

我在這裏使用name_Val ArrayAdapter adapter = new ArrayAdapter (this,android.R.layout.simple_list_item_1,name_Val); 最後 – Tony 2012-03-05 15:16:59

+1

好的,我沒有看到,對不起。你確定你的第一個入口不是空的?這是否解決了它? – WarrenFaith 2012-03-05 15:31:29

+1

在我的電話簿中,我沒有條目null(也許是我的第一個條目)因此,我不知道它是如何得到的,在開始的時候是空的 – Tony 2012-03-05 15:43:07