Contactactivity:
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 android.app.Activity; One import Android.content.ContentResolver; A import android.database.Cursor; - import Android.net.Uri; - import Android.os.Bundle; the import Android.provider.CallLog; - import Android.support.v4.widget.SimpleCursorAdapter; - 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 (R.id.phone_listview); theaddresslist=NewArraylist<map<string,string>>(); +Adapter=NewSimpleadapter ( This, Addresslist,r.layout.phone_message, A Newstring[]{"ID","name","Phonenum"}, the New int[]{r.id.phone_id,r.id.name_phone,r.id.num_phone}]; + - 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}
Simpleadapter:
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