【发布时间】:2018-09-08 03:53:53
【问题描述】:
btn_add_from_contacts.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
builder = new AlertDialog.Builder(getActivity());
View view = getLayoutInflater().inflate(R.layout.layout_add_from_contacts, null);
builder.setView(view);
/* ********************* */
phones = getActivity().getApplication().getContentResolver().query
(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null, null, null, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC");
String name,phoneNumber;
while(phones.moveToNext()) {
name = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
Log.w("","Names: " +name+"\nPhone: "+phoneNumber);
alertDialog = builder.create();
alertDialog.show();
}
/* ********************* */
}
});
这是代码,我想要的只是在此处显示我的手机联系人。我只是在 while 循环中显示它一次,但它没有给我任何输出。此外,我正在使用片段。如果有人知道代码有什么问题,请帮助我。
这里是 Logcat:
03-29 09:14:29.475 16754-16759/com.example.nomanikram.epilepsyseizuredetection I/zygote: Increasing code cache capacity to 1024KB
03-29 09:14:31.342 16754-16754/com.example.nomanikram.epilepsyseizuredetection W/InputEventReceiver:尝试完成输入事件,但输入事件接收器已被释放。 03-29 09:14:31.343 16754-16754/com.example.nomanikram.epilepsyseizuredetection W/ViewRootImpl [MainActivity]:由于根视图被删除而导致的丢弃事件:MotionEvent { action=ACTION_UP,actionButton=0,id[0]= 0, x[0]=116.09668, y[0]=382.5547, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=10351594 , 停机时间=10351588, deviceId=0, 源=0x1002 } 03-29 09:14:31.343 16754-16754/com.example.nomanikram.epilepsyseizuredetection W/InputEventReceiver:尝试完成输入事件,但输入事件接收器已被释放。
【问题讨论】:
-
显示你的 Logcat ..
-
alertDialog = builder.create(); alertDialog.show();--> 为什么在while循环中使用 -
我只是把它放在循环中进行测试。
标签: android listview android-fragments android-alertdialog android-contacts