我厌倦了在自定义列表视图中显示自定义对话框。请帮忙
代码:
more.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Dialog dialog = new Dialog(mContext.getApplicationContext());
dialog.setTitle("Discription");
dialog.setContentView(R.layout.dialog_item_simple_text);
TextView textViewItem = (TextView) dialog
.findViewById(R.id.textViewItem);
textViewItem.setText(data.short_description);
dialog.setCancelable(true);
dialog.setCanceledOnTouchOutside(true);
dialog.show();//<--Error at this point
}
});
出现类似错误:LogCat Massage
FATAL EXCEPTION: main android.view.WindowManager$BadTokenException: Unable to add
window -- token null is not for an application
at android.view.ViewRootImpl.setView(ViewRootImpl.java:563)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:269)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at android.app.Dialog.show(Dialog.java:281)
at com.fashionbargains.adapter.DnSAdapter$1.onClick(DnSAdapter.java:88)
at android.view.View.performClick(View.java:4240)
at android.view.View$PerformClick.run(View.java:17721)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
我有自定义适配器类,它是通过BaseTask
扩展AsyncTask
类调用的类