基本的に、ダイアログのボタンに OnClickListener を追加しようとしていますが、リスナーを追加するだけでアプリが不安定になりクラッシュし、キャッチしようとすると返されるメッセージが null になります。私の問題を見ていただきありがとうございます。
また、それが役立つ場合、これはメニューボタンが押されたときにトリガーされています。
ダイアログの作成:
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();
}
(少しトリミング) XML ファイル:
<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>