如何从联系人列表中显示的名字在Android的应用程序的ListView应用程序、联系人、名字、列表中

2023-09-04 06:21:19 作者:比风冷

如何从联系人列表中的Andr​​oid应用程序中显示的名字,以列表视图

解决方案

 公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);


    //我们将定义一个定制的屏幕布局位置(如上所示),但
    //通常情况下,你可以只使用标准的ListActivity布局。
    的setContentView(R.layout.contacts_list_item);

    光标mCursor = getContentResolver()查询(Data.CONTENT_URI,
                    空,//投影
                    空,//选择
                    空,// selectionArgs两个
                    Data.DISPLAY_NAME); // 排序

    startManagingCursor(mCursor);



    //现在创建一个新的列表适配器绑定到光标。
    // SimpleListAdapter被设计用于结合到一个光标。
    contactAdapter =新SimpleCursorAdapter(
            对此,语境//。
            android.R.layout.two_line_list_item,//指定排模板使用(在这里,两列开往两个检索光标行)。
            mCursor,//通行证光标结合。
            新的String [] {} Data.DISPLAY_NAME,//光标柱阵列结合。
            新的INT [] {android.R.id.text1}); //该模板对象的并行阵列绑定到这些列。

    //绑定到我们新的适配器。
    setListAdapter(contactAdapter);

}
 

如果你想显示联系人的姓名和电话号码既然后更改contactAdapter值

  contactAdapter =新SimpleCursorAdapter(
            对此,语境//。
            android.R.layout.two_line_list_item,//指定排模板使用(在这里,两列开往两个检索光标行)。
            mCursor,//通行证光标结合。
            新的String [] {Data.DISPLAY_NAME,ContactsContract.CommonDataKinds.Phone.NUMBER} //光标柱阵列结合。
            新的INT [] {android.R.id.text1,android.R.id.text2}); //该模板对象的并行阵列绑定到这些列。
 

快乐编码。

Android Framework Application Framework层简单介绍

how to display first name from contact list to listview in android application

解决方案

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


    // We'll define a custom screen layout here (the one shown above), but
    // typically, you could just use the standard ListActivity layout.
    setContentView(R.layout.contacts_list_item);

    Cursor mCursor = getContentResolver().query(Data.CONTENT_URI,
                    null,                       // projection
                    null,                       // selection
                    null,                       // selectionArgs
                    Data.DISPLAY_NAME);         // sortOrder        

    startManagingCursor(mCursor); 



    // Now create a new list adapter bound to the cursor.
    // SimpleListAdapter is designed for binding to a Cursor.
    contactAdapter = new SimpleCursorAdapter(
            this, // Context.
            android.R.layout.two_line_list_item,  // Specify the row template to use (here, two columns bound to the two retrieved cursor rows).
            mCursor,    // Pass in the cursor to bind to.
            new String[] {Data.DISPLAY_NAME},           // Array of cursor columns to bind to.
            new int[] {android.R.id.text1});  // Parallel array of which template objects to bind to those columns.

    // Bind to our new adapter.
    setListAdapter(contactAdapter);

}

if you want to display contact name and number both then change contactAdapter value as

contactAdapter = new SimpleCursorAdapter(
            this, // Context.
            android.R.layout.two_line_list_item,  // Specify the row template to use (here, two columns bound to the two retrieved cursor rows).
            mCursor,    // Pass in the cursor to bind to.
            new String[] {Data.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER},           // Array of cursor columns to bind to.
            new int[] {android.R.id.text1, android.R.id.text2});  // Parallel array of which template objects to bind to those columns.

happy coding.

 
精彩推荐
图片推荐