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();
}
/* ********************* */
}
});
Here it is the code, all I want is to display my contacts from phone as here. I am just displaying it in while loop once but it is not giving me any output. Further I am using fragment. If any one knows what's wrong with code just help me out.
Here is the 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: Attempted to finish an input event but the input event receiver has already been disposed. 03-29 09:14:31.343 16754-16754/com.example.nomanikram.epilepsyseizuredetection W/ViewRootImpl[MainActivity]: Dropping event due to root view being removed: 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, downTime=10351588, deviceId=0, source=0x1002 } 03-29 09:14:31.343 16754-16754/com.example.nomanikram.epilepsyseizuredetection W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed.