Reputation: 1939
I've some strange problem with my Android application. I'm creating AlertDialog
with two EditText
controls and some buttons (edit existing object).
@Override
public void onClick(View arg0) {
AlertDialog.Builder alert = new AlertDialog.Builder(mContext);
final View dialogLayout = mInflater.inflate(R.layout.event_edit, null);
alert.setView(dialogLayout);
((EditText)dialogLayout.findViewById(R.id.txtCompany)).setText(cEvent.getCompany());
((EditText)dialogLayout.findViewById(R.id.txtCity)).setText(cEvent.getCity());
alert.setTitle(R.string.DialogEditEventTitle);
alert.setPositiveButton(R.string.DialogEditEventDelete,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Delete action
}
});
alert.setNeutralButton(R.string.DialogEditEventSave,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Save
}
});
alert.setNegativeButton(R.string.DialogEditEventCancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Cancel action
}
});
AlertDialog dialog = alert.show();
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
}
If I try to change focus or put someting to edit text fields, then I get exception:
12-03 14:32:25.663 E/AndroidRuntime( 5074): FATAL EXCEPTION: main
12-03 14:32:25.663 E/AndroidRuntime( 5074): java.lang.IllegalArgumentException: parameter must be a descendant of this view
12-03 14:32:25.663 E/AndroidRuntime( 5074): at android.view.ViewGroup.offsetRectBetweenParentAndChild(ViewGroup.java:2627)
12-03 14:32:25.663 E/AndroidRuntime( 5074): at android.view.ViewGroup.offsetDescendantRectToMyCoords(ViewGroup.java:2564)
12-03 14:32:25.663 E/AndroidRuntime( 5074): at android.view.ViewRoot.scrollToRectOrFocus(ViewRoot.java:1508)
12-03 14:32:25.663 E/AndroidRuntime( 5074): at android.view.ViewRoot.draw(ViewRoot.java:1249)
12-03 14:32:25.663 E/AndroidRuntime( 5074): at android.view.ViewRoot.performTraversals(ViewRoot.java:1163)
12-03 14:32:25.663 E/AndroidRuntime( 5074): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
12-03 14:32:25.663 E/AndroidRuntime( 5074): at android.os.Handler.dispatchMessage(Handler.java:99)
12-03 14:32:25.663 E/AndroidRuntime( 5074): at android.os.Looper.loop(Looper.java:123)
12-03 14:32:25.663 E/AndroidRuntime( 5074): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-03 14:32:25.663 E/AndroidRuntime( 5074): at java.lang.reflect.Method.invokeNative(Native Method)
12-03 14:32:25.663 E/AndroidRuntime( 5074): at java.lang.reflect.Method.invoke(Method.java:521)
12-03 14:32:25.663 E/AndroidRuntime( 5074): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:871)
12-03 14:32:25.663 E/AndroidRuntime( 5074): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:629)
12-03 14:32:25.663 E/AndroidRuntime( 5074): at dalvik.system.NativeStart.main(Native Method)
What is the reason for this exception and how can I try to resolve it?
Upvotes: 1
Views: 426
Reputation: 490
Please try;
//first create, set soft input mode and then show//
AlertDialog dialog = alert.create();
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
dialog.show();
Upvotes: 1