(更新)这适用于模拟器,但不适用于我的HTC图例:(
我的ListActivity中有以下方法,并且它没有返回Cursor中的任何值(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();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
408 次 |
| 最近记录: |