我试图创建一个对话框,但是当我尝试运行代码时它崩溃了。我想在我的片段中的列表视图中选择一个项目时运行它,现在我只想尝试显示对话框而不传递任何内容
这是我的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