ダイアログを作成しようとしましたが、コードを実行しようとするとクラッシュします。フラグメントにあるリストビューのアイテムを選択したときに実行したいのですが、今は何も渡さずにダイアログを表示したいだけです
ここに私のJavaコードがあります:
myInfoList.setAdapter(new CustomAdapter(details , getActivity().getApplicationContext()));
myInfoList.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
//System.out.println("Name: "+details.get(position).getSub();
//String s = details.get(position).getDescription();
final Dialog dialog = new Dialog(getActivity().getApplicationContext());
dialog.setContentView(R.layout.purchase);
dialog.setTitle("Title");
Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
});
ログキャット:
07-06 12:05:16.012: V/21st Polling:(12319): clicked
07-06 12:05:16.957: D/AndroidRuntime(12319): Shutting down VM
07-06 12:05:16.957: W/dalvikvm(12319): threadid=1: thread exiting with uncaught exception (group=0x40e20930)
07-06 12:05:16.972: E/AndroidRuntime(12319): FATAL EXCEPTION: main
07-06 12:05:16.972: E/AndroidRuntime(12319): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
07-06 12:05:16.972: E/AndroidRuntime(12319): at android.view.ViewRootImpl.setView(ViewRootImpl.java:571)
07-06 12:05:16.972: E/AndroidRuntime(12319): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:246)
07-06 12:05:16.972: E/AndroidRuntime(12319): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
07-06 12:05:16.972: E/AndroidRuntime(12319): at android.app.Dialog.show(Dialog.java:281)
07-06 12:05:16.972: E/AndroidRuntime(12319): at com.example.isellcrazyitem.SalesOrder$1.onItemClick(SalesOrder.java:104)
07-06 12:05:16.972: E/AndroidRuntime(12319): at android.widget.AdapterView.performItemClick(AdapterView.java:298)
07-06 12:05:16.972: E/AndroidRuntime(12319): at android.widget.AbsListView.performItemClick(AbsListView.java:1102)
07-06 12:05:16.972: E/AndroidRuntime(12319): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2751)
07-06 12:05:16.972: E/AndroidRuntime(12319): at android.widget.AbsListView$1.run(AbsListView.java:3426)
07-06 12:05:16.972: E/AndroidRuntime(12319): at android.os.Handler.handleCallback(Handler.java:725)
07-06 12:05:16.972: E/AndroidRuntime(12319): at android.os.Handler.dispatchMessage(Handler.java:92)
07-06 12:05:16.972: E/AndroidRuntime(12319): at android.os.Looper.loop(Looper.java:137)
07-06 12:05:16.972: E/AndroidRuntime(12319): at android.app.ActivityThread.main(ActivityThread.java:5233)
07-06 12:05:16.972: E/AndroidRuntime(12319): at java.lang.reflect.Method.invokeNative(Native Method)
07-06 12:05:16.972: E/AndroidRuntime(12319): at java.lang.reflect.Method.invoke(Method.java:511)
07-06 12:05:16.972: E/AndroidRuntime(12319): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799)
07-06 12:05:16.972: E/AndroidRuntime(12319): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
07-06 12:05:16.972: E/AndroidRuntime(12319): at dalvik.system.NativeStart.main(Native Method)
07-06 12:05:18.613: I/Process(12319): Sending signal. PID: 12319 SIG: 9