2012-12-03 2 views
1

J'ai un problème étrange avec mon application Android. Je crée AlertDialog avec deux contrôles EditText et quelques boutons (modifier l'objet existant).Plantages aléatoires dans AlertDialog

@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); 

} 

Si j'essaie de changer d'orientation ou mettre someting modifier les champs de texte, puis je me 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) 

Quelle est la raison de cette exception et comment puis-je essayer de le résoudre?

+0

-t-il se bloque toujours si vous supprimez la partie sur le mode d'entrée doux? – njzk2

+0

Oui. J'ai mis cette ligne pendant mes investigations liées à mon problème. Dans les deux cas, j'ai le même résultat - au-dessus de l'exception. – Grzegorz

+0

@Grzegorz: voir http://stackoverflow.com/questions/7100555/preventing-catching-illegalargumentexception-parameter-must-be-a-descendant-ofpost peut-être utile –

Répondre

1

Veuillez essayer;

//first create, set soft input mode and then show// 

AlertDialog dialog = alert.create();  
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); 
dialog.show(); 
+0

Dans ce cas, j'ai également mon application s'est écrasé. Enfin, je change d'approche pour présenter cette fonctionnalité de la boîte de dialogue à l'écran normal. Ensuite, tout commence à bien fonctionner. – Grzegorz

Questions connexes