我需要一些帮助。我只需要获取此联系人列表中移动类型的号码。
使用此代码,我提取所有数字,相反,我只需要采用移动类型......并将它们显示在列表中。 帮助我,提前致谢!
代码:
void ReadContacts(String sort) {
final Uri uri = Phone.CONTENT_URI;
final String[] projection = new String[] {
Contacts._ID,
Phone.NUMBER,
Contacts.DISPLAY_NAME,
Phone.TYPE
};
String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '1'";
String[] selectionArgs = null;
final String sortOrder = Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
m_curContacts = managedQuery(uri, projection, selection, selectionArgs, sortOrder);
String[] fields = new String[] {Contacts.DISPLAY_NAME, Phone.NUMBER};
m_slvAdapter = new SimpleCursorAdapter(this,R.layout.simple_list_item_mio,m_curContacts,fields,
new int[] {R.id.text1, R.id.text2});
m_slvAdapter.setFilterQueryProvider(new FilterQueryProvider() {
public Cursor runQuery(CharSequence constraint) {
Log.d(LOG_TAG, "runQuery constraint:"+constraint);
String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '1'" +
" AND "+ Contacts.DISPLAY_NAME + " LIKE '%"+constraint+"%'";
String[] selectionArgs = null;//new String[]{"'1'"};//, };
Cursor cur = managedQuery(uri, projection, selection, selectionArgs, sortOrder);
return cur;
}
});
ps:Phone.TYPE mobile 为 int 2。
最佳答案
将 Selection 和 SelectionArg 设置为以下内容:
selection="ContactsContract.Contacts.IN_VISIBLE_GROUP =? and Phone.TYPE=?";
selectionArgs=new String[]{"1", "2"};
关于java - Android:联系人电话.TYPE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10051084/