Fondamentalement, j'essaie d'ajouter un OnClickListener à un bouton dans une boîte de dialogue, mais en ajoutant simplement l'écouteur, l'application devient instable et se bloque, et quand j'essaie et l'attraper, le message retourné est nul. Merci d'avoir jeté un coup d'oeil à mon problème.Android - Erreur lors de l'ajout d'un OnClickListener à un bouton dans une boîte de dialogue
De plus, si cela vous aide, cela est déclenché quand vous appuyez sur un bouton de menu.
Création du dialogue:
try {
final Dialog dialog = new Dialog(List.this);
dialog.setContentView(R.layout.adddialog);
dialog.setTitle("Add to the list");
dialog.setCancelable(true);
final EditText et = (EditText) findViewById(R.id.itemAddDialog);
Button ok = (Button) findViewById(R.id.okAddDialog);
Button cancel = (Button) findViewById(R.id.cancelAddDialog);
ok.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
//Contents of this function don't matter, It freezes simply by being created
}
});
dialog.show();
}
catch (Exception e) {
Toast.makeText(List.this, e.getMessage(), Toast.LENGTH_LONG).show();
}
fichier XML (Légèrement coupé):
<LinearLayout
android:id="@+id/btnpaneAddDialog"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal" >
<Button
android:id="@+id/okAddDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add it" />
<Button
android:id="@+id/cancelAddDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel" />
</LinearLayout>
Wow, merci! J'essayais d'envelopper ma tête autour de celui-ci toute la journée! Merci! –
assurez-vous de marquer sa réponse comme la bonne, et donnez-lui un upvote pour la postérité;) – MattC