0
到ListView控件如何從聯繫人列表中顯示的名字在Android應用程序如何從聯繫人列表中顯示的名字在Android應用程序
到ListView控件如何從聯繫人列表中顯示的名字在Android應用程序如何從聯繫人列表中顯示的名字在Android應用程序
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);
}
到ListView的,如果你想顯示聯繫人姓名和電話號碼都然後更改contactAdapter值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.
快樂編碼。