Android obtains the contact list

Source: Internet
Author: User

 

 

Code Package contacts. List;

Import Android. App. listactivity;
Import Android. database. cursor;
Import Android. provider. Contacts. People;
Import Android. OS. Bundle;
Import Android. widget. listadapter;
Import Android. widget. simplecursoradapter;

/**
*
* Data comes from a cursor.
*/
Public class contactslist extends listactivity {

@ Override
Protected void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );

// Get a cursor with all people
Cursor c = getcontentresolver (). Query (people. content_uri, null );
Startmanagingcursor (C );

Listadapter adapter = new simplecursoradapter (this,
// Use a template that displays a Text View
Android. R. layout. simple_list_item_1,
// Give the cursor to the list adatper
C,
// Map the name column in The People database...
New String [] {People. name },
// The "text1" view defined in the XML template
New int [] {Android. R. Id. text1 });
Setlistadapter (adapter );
}
}

Code <? XML version = "1.0" encoding = "UTF-8" ?>
< Manifest Xmlns: Android = "Http://schemas.android.com/apk/res/android"
Package = "Contacts. List"
Android: versioncode = "1"
Android: versionname = "1.0" >
< Uses-Permission Android: Name = "Android. Permission. read_contacts"   />
< Application Android: icon = "@ Drawable/icon" Android: Label = "@ String/app_name" >
< Activity Android: Name = ". Contactslist"
Android: Label = "@ String/app_name" >

< Intent-Filter >
< Action Android: Name = "Android. Intent. Action. Main"   />
< Category Android: Name = "Android. Intent. Category. sample_code"   />
</ Intent-Filter >
</ Activity >

</Application>

</Manifest> 

It was a simple thing, but it took me a lot of effort. It turned out to be a problem with the configuration file, and later it was a base class inheritance error. In any case, it was okay.

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.