1

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?

BryanH
  • 5,826
  • 3
  • 34
  • 47
Gie
  • 1,907
  • 2
  • 24
  • 49
  • does it still crashes if you remove the part about the soft input mode ? – njzk2 Dec 03 '12 at 17:36
  • Yes. I've put this line during my investigations related to my problem. In both cases I get the same result - above exception. – Gie Dec 03 '12 at 17:41
  • @Grzegorz : see http://stackoverflow.com/questions/7100555/preventing-catching-illegalargumentexception-parameter-must-be-a-descendant-of post maybe helpful – ρяσѕρєя K Dec 03 '12 at 17:43
  • I saw this thread, but unfortunatly proposed solution doesn't work for me. – Gie Dec 03 '12 at 17:59

1 Answers1

1

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();
IAmGroot
  • 13,760
  • 18
  • 84
  • 154
cirit
  • 490
  • 5
  • 10
  • In this case I also my app crashed. Finally I change approach to presenting this functionality from dialog to normal screen. Then everything starts working ok. – Gie Dec 20 '12 at 16:02