这是我展示ListPopupWindow
的代码listPopupWindow = new ListPopupWindow(this);
listPopupWindow.setAnchorView(this.findViewById(android.R.id.content));
final String[]messages = new String[MsgFromApp.getMessages().length];
final ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, messages);
final AdapterView.OnItemClickListener itemClickListener = new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
listPopupWindow.dismiss();
listPopupWindow = null;
}
};
listPopupWindow.setModal(true); listPopupWindow.setListSelector(getResources().getDrawable(R.drawable.message));
listPopupWindow.setAdapter(adapter);
listPopupWindow.setOnItemClickListener(itemClickListener);
listPopupWindow.show();
它提供以下例外: 引起:android.view.WindowManager $ BadTokenException:无法添加窗口 - 令牌null无效;你的活动在运行吗?
这有什么问题? &安培;如何解决这个问题?
答案 0 :(得分:0)
当应用程序尝试通过打开对话框从后台线程(AsyncTask)通知用户时,会发生此异常。 请检查此链接:https://stackoverflow.com/a/18665887/4848308