Android easy to get contacts

Source: Internet
Author: User


1 Package Com.example.practice5_service;2 3 import java.util.ArrayList;4 import Java.util.HashMap;5 import java.util.List;6 import Java.util.Map;7 8 import Com.example.adapter.simpleAdapter;9 Ten import; One import Android.content.ContentResolver; A import android.database.Cursor; - import; - import Android.os.Bundle; the import Android.provider.CallLog; - import; - import Android.view.Menu; - import Android.view.MenuItem; + import Android.widget.ListAdapter; - import Android.widget.ListView; +  A  Public classContactactivity extends Activity { at     PrivateListView Phone_listview; -     PrivateList<map<string,string>>AddressList; -     PrivateSimpleadapter Adapter; -      -     PrivateListAdapter Listadaper; -     PrivateContentresolver Resolver; in @Override -     protected voidonCreate (Bundle savedinstancestate) { to super.oncreate (savedinstancestate); + Setcontentview (r.layout.activity_contact); - Initview (); the LoadData (); *     } $ Panax Notoginseng      Public voidInitview () { -phone_listview=(ListView) Findviewbyid (; theaddresslist=NewArraylist<map<string,string>>(); +Adapter=NewSimpleadapter ( This, Addresslist,r.layout.phone_message, A                 Newstring[]{"ID","name","Phonenum"}, the                 New int[]{,,}]; +          - Phone_listview.setadapter (adapter); $     } $      Public voidLoadData () { -         //content recipients get data from the content provider -Resolver=super.getcontentresolver ();//get Contentresolver, there is a method to increase and revise the search theCursor Result=resolver.query (CallLog.Calls.CONTENT_URI,NULL,NULL,NULL,NULL);//get information on Calllog.content_uri -          while(Result.movetonext ()) {WuyiMap<string,string> row=NewHashmap<string, string>(); the             intId=Result.getint (Result.getcolumnindex (calllog.calls._id)); -String name=result.getstring (Result.getcolumnindex (CallLog.Calls.CACHED_NAME)); WuString phonenum=result.getstring (Result.getcolumnindex (CallLog.Calls.NUMBER)); -Row.put ("ID", string.valueof (ID)); AboutRow.put ("name", name); $Row.put ("Phonenum", phonenum); - addresslist.add (row); -         } - result.close (); A adapter.notifydatasetchanged (); +     } the}


1 Package Com.example.adapter;2 3 import java.util.List;4 import Java.util.Map;5 6 import Android.content.Context;7 import Android.view.View;8 import Android.view.ViewGroup;9 import Android.widget.BaseAdapter;Ten import Android.widget.SimpleAdapter; One  A  Public classSimpleadapter extends Simpleadapter { -  -      PublicSimpleadapter (context context, list<? extends Map<string,?>>data, the             intResource, string[] from,int[] to) { -Super (context, data, resource, from, to); -         //TODO auto-generated Constructor stub -     } +}

Android easy to get contacts

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: 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.