如何从Android中的联系人获取10 -10个联系人 [英] how to get 10 -10 contacts from contact in android
问题描述
在我的应用中,我只需要提取10个联系人,当我按下下一步"按钮等等时,接下来的10个联系人就会被提取.
here in my app i need to fetch only 10 contacts and next 10 contacts will fetch when I press next button and so on..
protected String doInBackground(String... args) {
i = 0;
count = 0;
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
null, null, null);
names = new String[cur.getCount()];
phone = new String[cur.getCount()];
if ((cur.getCount() > 0)) {
if (count < 5) {
while (cur.moveToNext()) {
String id = cur.getString(cur
.getColumnIndex(ContactsContract.Contacts._ID));
String name = cur
.getString(cur
.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
if (Integer
.parseInt(cur.getString(cur
.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
Cursor pCur = cr
.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null,
ContactsContract.CommonDataKinds.Phone.CONTACT_ID
+ " = ?",
new String[] { id }, null);
while (pCur.moveToNext() && i < 5) {
String phoneNo = pCur
.getString(pCur
.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
names[i] = name;
phone[i] = phoneNo;
if (i == 0)
fulldata += "\"" + i + "\"" + ":" + "{"
+ "\"" + "phone" + "\"" + ":"
+ "\"" + phoneNo + "\"" + "}";
else
fulldata += "," + "\"" + i + "\"" + ":"
+ "{" + "\"" + "phone" + "\"" + ":"
+ "\"" + phoneNo + "\"" + "}";
i++;
}
pCur.close();
}
count++;
}
}
}
return null;
}
// {_action:addcontacts,contacts:{"0":{"phone":"8098098"},"1":{"phone":"8098090"},"2":{"phone":"8096879"}}}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
fulldata += "}";
Log.i("all data to post", "" + fulldata);
new UpdateContacts().execute();
}
}
我正在从此代码块中获取所有联系人,但我需要获取列表中特定(10)个联系人,当我单击"next"按钮时,它应该获取下一个(10个数字)联系人列表
I am getting all contacts from this code block but i need to fetch specific(10) number of contact in list and when I click on next button that time it should fetch next (10 numbers)list of number
推荐答案
我会使用LIMIT函数.
I would go for LIMIT function.
SELECT * FROM table LIMIT 10
->获得1st 10条记录
SELECT * FROM table LIMIT 10
--> get 1st 10 records
SELECT * FROM table LIMIT 10, 10
->在第10行之后获得10条记录
SELECT * FROM table LIMIT 10, 10
--> get 10 records after row 10
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, "LIMIT 10, " + count);
count += 10;
希望这会有所帮助.
这篇关于如何从Android中的联系人获取10 -10个联系人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!