开发者

Android ContactsContract Result to ListView

Need help on how Im going to put the results of my code into a listview. Im having trouble following/modifying the samples fro开发者_StackOverflow社区m the android documentation. So I got this code from a tutorial and it does return the contacts from my phone (use a device for debugging) but it only shows it as a log in logcat.

package com.olecontacts.sirje;

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.provider.ContactsContract.PhoneLookup;
import android.util.Log;

public class OleContactsActivity extends Activity{
    /** Called when the activity is first created. */

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        final String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
        Cursor people = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, sortOrder);
        //String[] fields = new String[] {ContactsContract.Data.DISPLAY_NAME};      
        while(people.moveToNext()){
            int nameIndex = people.getColumnIndex(PhoneLookup.DISPLAY_NAME);
            String name = people.getString(nameIndex);
            Log.d("CONTACTS", name);
        }      
    }
}

thanks in advance!


thanks. so how should i use this vector string then? i dont know much about java to be honest. i tried putting the results of people.getString(nameIndex) into a string array but it wouldnt let me. it has errors and force closes my app.


You have to take one vector of type string

Then allocate memory

Add the contacts to vector of type string (In the place of log)

And then show results of vector in a listview . Here you can found the example of listview binding.

http://androidcodesnips.blogspot.com/2011/04/android-custom-listview.html

Even you need any help then tell me. I will give example with your code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜