[英]how to get the separate contact name array list and contact number array list from the device
ArrayList<String> contacts_list = new ArrayList<String>();
Cursor c = getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
null, null, null);
while (c.moveToNext()) {
contactName = c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
PhoneNumber = c
.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
contacts_list.add("ContactName:"+contactName + "\n" +"ContactNumber:"+PhoneNumber );
}
c.close();
In above code,getting the name and phone number but not separating the arraylist of contact number and names 在上面的代码中,获取姓名和电话号码,但不分离联系号码和姓名的arraylist
create two lists 创建两个列表
ArrayList<String> contacts_name = new ArrayList<String>();
ArrayList<String> contacts_number = new ArrayList<String>();
Cursor c = getContentResolver().query(
ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
null, null, null);
while (c.moveToNext()) {
contactName = c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
PhoneNumber = c
.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
contacts_name.add("ContactName:"+contactName);
contacts_number.add("ContactNumber:"+PhoneNumber );
}
c.close();
Create a class like this 创建一个这样的类
public class NameContact {
private String name;
private String contact;
public NameContact(String name, String contact) {
this.name = name;
this.contact = contact;
}
public String getName() {
return name;
}
public String getContact() {
return contact;
}
}
then make an arraylist of it and add items in it.. 然后制作它的arraylist并在其中添加项目..
ArrayList<NameContact> abc = new ArrayList<NameContact>();
abc.add(new NameContact("your_name","your_contact"));
Then After to put in RequestParams use this 然后输入RequestParams后使用它
RequestParams params = new RequestParams();
JSONArray arrayName = new JSONArray();
JSONArray arrayContact = new JSONArray();
for(i = 0;i < contacts.size();i++ ) {
arrayName.put(contacts.get(i).getName());
arrayContact.put(contacts.get(i).getContact());
}
params.put("ContactNameArray",arrayName);
params.put("ContactNumberArray",arrayContact);
You should go with pojo class or at the moment u can use this: 你应该去pojo课程,或者你可以使用这个:
Arraylist<HashMap<String,String>> arr_list=new Arraylist<HashMap<String,String>>();
arr_list.clear();
Cursor c=getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null, null, null);
while (c.moveToNext()) { while(c.moveToNext()){
contactName = c.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
PhoneNumber = c
.getString(c.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
HashMap<String,String> map=new HashMap<String,String>();
map.put("name",""+contactName);
map.put("number",""+PhoneNumber);
arr_list.add(map);
}
c.close();
Log.d("array","arr="+arr_list); Log.d( “阵列”, “ARR =” + arr_list);
you will have two keys and values with the position of array u can get the separate values. 你将有两个键和值与数组的位置u可以得到单独的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.