0

我如何從列表視圖中獲取uri的聯繫人詳細信息? 。我已經從列表視圖中獲得了所選聯繫人的聯繫人URI。下面的代碼片段是我嘗試過的,但不起作用。更令人驚訝的是,日誌記錄甚至沒有執行!如何從列表視圖中從onItemClick()獲取的列表項的聯繫人Uri中檢索數據?

@Override 
public void onItemClick(
    AdapterView<?> parent, View item, int position, long rowID) { 
    // Get the Cursor 
    Cursor cursor = ((SimpleCursorAdapter) parent.getAdapter()).getCursor(); 
    // Move to the selected contact 
    cursor.moveToPosition(position); 
    // Get the _ID value 
    mContactId = cursor.getLong(CONTACT_ID_INDEX); 
    // Get the selected LOOKUP KEY 
    mContactKey = cursor.getString(CONTACT_KEY_INDEX); 
    // Create the contact's content Uri 
    mContactUri = Contacts.getLookupUri(mContactId, mContactKey); 
    // ListView Clicked item index 

    String id=new String(); 
    String name = new String(); 
    String hasPhone = new String(); 
    int idx; 

    Cursor cursor1 = getActivity().getContentResolver().query(mContactUri, null, null, null, null); 
    { 
     idx = cursor1.getColumnIndex(ContactsContract.Contacts._ID); 
     id = cursor1.getString(idx); 

     idx = cursor1.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME); 
     name = cursor1.getString(idx); 

     idx = cursor1.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER); 
     hasPhone = cursor1.getString(idx); 
    } 
    Log.i("Phone Number","The phone number is: "+hasPhone); 
    Log.i("Name","The name is: "+name); 
    /* 
    * You can use mContactUri as the content URI for retrieving 
    * the details for a contact. 
    */ 
} 

這是列表視圖項目被點擊的特定時間的日誌。

09-05 21:55:07.663: I/am_on_resume_called(25140): [0,com.laer.okgo.PersonListActivity] 
09-05 21:55:07.738: W/Adreno-GSL(25140): <ioctl_kgsl_device_getproperty:663>: mmap failed: errno 22 Invalid argument 
09-05 21:55:07.738: I/Adreno-EGL(25140): <qeglDrvAPI_eglInitialize:320>: EGL 1.4 QUALCOMM Build: I10246dbd022c719c705be805d5642cc8fdfbd2a2Date: 03/10/14 
09-05 21:55:07.739: I/CanvasContext(25140): Initialized EGL, version 1.4 
09-05 21:55:13.932: I/ImageButton(25140): Clicked!! 

這是列表視圖顯示它是由一個ImageButton

09-05 21:55:13.941: I/am_on_paused_called(25140): [0,com.laer.okgo.PersonListActivity] 

這是當我點擊列表項開始後。

09-05 21:55:17.825: I/am_on_resume_called(25140): [0,com.laer.okgo.PersonListActivity] 

另外一個獎金問題。我如何更改列表視圖的主題/樣式?如果有人能指引我正確的方向,這將是很好的!

+0

你usign'OnItemClickListener'或'OnListItemClick()'listiner爲'ListView' – 2014-09-05 17:55:46

+0

'OnListItemClick()'不以'LoaderManager.LoaderCallbacks工作,因爲我使用的是'AdapterView' '接口。此整個代碼也在一個片段中。 – Boggartfly 2014-09-05 18:02:18

+0

[ListView樣式](http://www.androprogrammer.com/2013/10/styles-for-list-view-in-android.html)或查看[AndroidHive](http://www.androidhive。 info/2012/02/android-custom-listview -with-image-and-text /) – 2014-09-05 18:02:58

回答

0

現在這真的是我的錯。我點擊了錯誤的UI元素。有兩個名稱相似的按鈕。我沒有意識到這一點。大聲笑我搞砸了大時間!浪費了很多時間... 故事的寓意讓您的UI/UX元素保持獨特且易於區分的名稱!

相關問題