1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| package com.example.rc;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.widget.ListView;
public class MainnActivity extends Activity {
TextView f=null;
ListView vue;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
List<String []> laliste=new ArrayList<String[]>() ;
vue =(ListView) findViewById(R.id.listView);
android.database.Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
String nom ="";
String n ="";
String num ="";
int id ;int idIdx;
int detectnum;
while (cursor.moveToNext()){
idIdx = cursor.getInt(cursor.getColumnIndex(ContactsContract.Contacts._ID));
detectnum=cursor.getInt(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
if (detectnum>=1){
android.database.Cursor cursor2 = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID+"="+idIdx, null, null);
while (cursor2.moveToNext()){
nom=cursor2.getString(cursor2.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
int numero2=cursor2.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
num=num+cursor2.getString(numero2);}
}
String[] repertoir={nom,num};
laliste.add(repertoir);
}
RepertoireAdapter a=new RepertoireAdapter(this,laliste);
vue.setAdapter(a);
cursor.close();
}
} |
Partager