【发布时间】:2012-01-04 06:53:13
【问题描述】:
所以这与我之前提出的一个问题有关。我正在尝试使用指定的布局显示警报。我的布局是:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp">
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textColor="#FFF" />
</LinearLayout>
调用和显示警告对话框的代码是:
Context mContext = getApplicationContext();
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
// use a custom View defined in xml
View view = LayoutInflater.from(mContext).inflate(R.layout.sell_dialog, (ViewGroup) findViewById(R.id.layout_root));
builder.setView(view);
builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// do whatever you want with the input
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
当我运行它时,我收到一条错误消息:
未捕获的处理程序:线程主因未捕获的异常而退出 android.view.WindowManager$NadTokenException: 无法添加窗口 -- 令牌 null 不适用于应用程序
我浏览了 android 开发网站,但无法弄清楚。我想我只是错过了一些明显的东西,但修复并没有跳出来。如何显示此警报对话框?
【问题讨论】:
标签: android