我正在使用“Calls.CONTENT_URI”内容提供商。我已经重新检索了列名,但现在我想让这个内容提供商中的列名为“name”的所有名称。
我的代码如下:
uri = Calls.CONTENT_URI;
String[] projection = {"name"};
String selection = null;
String[] selectionArgs = null;
String sort = null;
resolver = getContentResolver();
cursor = resolver.query(uri, projection, selection, selectionArgs, sort);
Log.i("TUTORIAL", "counts :"+cursor.getCount());
String s;
cursor.moveToFirst();
for(int x=0; x<cursor.getCount(); x++){
s = cursor.getString(x);
Log.i("TUTORIAL", ""+s);
//cursor.moveToNext();
}
但是这只追溯了一个名字。我想列出保存在手机中的所有名字,如:
约翰 彼得 标记 苏茜 。 。 X
但现在我只得到一个名字:
彼得。 希望我已经足够清楚了。
有什么问题?提前感谢您的帮助。
答案 0 :(得分:0)
我认为这会对你有帮助
ArrayList<String> nameList = new ArrayList<String>();
String[] projection = {"name"};
String selection = null;
String[] selectionArgs = null;
String sort = null;
resolver = getContentResolver();
cursor = resolver.query(uri, projection, selection, selectionArgs, sort);
Log.i("TUTORIAL", "counts :"+cursor.getCount());
String s;
if(cursor.moveToFirst()) {
do {
nameList.add(cursor.getString(0));
//your code
//s = cursor.getString(x);
Log.i("TUTORIAL", ""+cursor.getString(0));
}while(cursor.moveToNext());
}
答案 1 :(得分:0)
你可以尝试这个,它对我有用:
public void readContacts() {
Cursor cur = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null,
null, null, null);
if (cur.getCount() > 0) {
while (cur.moveToNext()) {
if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
// Get contact id (id)
String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
// Get contact name (displayName)
String displayName = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
}
}
}
cur.close();
}
答案 2 :(得分:0)
这是代码。
public override View GetChildView(int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent)
{
var SecondLevelexplv = new CustExpListview(Application.Context);
SecondLevelexplv.SetAdapter(new SecondLevelAdapter(context));
SecondLevelexplv.SetGroupIndicator(null);
SecondLevelexplv.GroupExpand += SecondLevelexplv_GroupExpand;
SecondLevelexplv.GroupCollapse += SecondLevelexplv_GroupCollapse;
return SecondLevelexplv;
}
private void SecondLevelexplv_GroupCollapse(object sender, ExpandableListView.GroupCollapseEventArgs e)
{
AbsListView.LayoutParams lp = new AbsListView.LayoutParams(AbsListView.LayoutParams.MatchParent, 70);
(sender as CustExpListview).LayoutParameters = lp;
}
private void SecondLevelexplv_GroupExpand(object sender, ExpandableListView.GroupExpandEventArgs e)
{
//expand the group and the height is the `children count` * `unit height`
AbsListView.LayoutParams lp = new AbsListView.LayoutParams(AbsListView.LayoutParams.MatchParent, 70 * 5);
(sender as CustExpListview).LayoutParameters = lp;
}
}