【发布时间】:2012-02-05 00:56:02
【问题描述】:
(更新)这适用于模拟器,但不适用于我的 HTC 传奇 :(
我的 ListActivity 中有以下方法,但它没有返回光标中的任何值 (getCount=0)
我不知道为什么。在我的列表中单击哪个联系人并不重要。
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
Log.d(TAG,"onListItemClick");
//get Telephone number for entry and display in Toast
Uri phoneUri = ContentUris.withAppendedId(Phone.CONTENT_URI, id);
Log.d(TAG,String.valueOf(phoneUri));
String[] projection = new String[]{Phone.NUMBER};
//Get Cursor
Cursor phoneCursor = managedQuery(phoneUri, projection, null, null, null);
while(phoneCursor.moveToNext()){
String dspNumber;
String number = phoneCursor.getString(phoneCursor.getColumnIndexOrThrow(Phone.NUMBER));
if(number==""){
dspNumber = "No number found";
}else{
dspNumber = number;
}
Toast.makeText(this,dspNumber, 3000).show();
}
}
【问题讨论】:
-
您设备的 API 级别是多少?
-
尽量不要使用id。我的意思是尝试获取所有条目。也许问题是您使用了错误的 id
-
您确定您没有使用另一个表的 id,例如 raw_contact 表而不是数据表吗?