Android 已修复微调器的BadTokenException错误,但现在文本视图未显示在布局中。如何解决这两个问题?

Android 已修复微调器的BadTokenException错误,但现在文本视图未显示在布局中。如何解决这两个问题?,android,layout,spinner,Android,Layout,Spinner,我有一个与微调器的对话框 AlertDialog.Builder customDialog = new AlertDialog.Builder(this); LayoutInflater layoutInflater = (LayoutInflater) getApplicationContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v

我有一个与微调器的对话框

        AlertDialog.Builder customDialog = new AlertDialog.Builder(this);
        LayoutInflater layoutInflater = (LayoutInflater) getApplicationContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view = layoutInflater.inflate(R.layout.jquery_dialog, null);
        final EditText idTxt = (EditText) view.findViewById(R.id.idName);
        final Spinner themeSpinner = (Spinner) view
                .findViewById(R.id.themeSpinner);
        final CheckBox headerChk = (CheckBox) view.findViewById(R.id.headerChk);
        final CheckBox footerChk = (CheckBox) view.findViewById(R.id.footerChk);
        final RadioGroup group = (RadioGroup) view
                .findViewById(R.id.jqmNavigation);
        customDialog.setView(idTxt);
        customDialog.setView(headerChk);
        customDialog.setView(footerChk);
        themeSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1,
                    int arg2, long arg3) {
                // TODO Auto-generated method stub
                themes = getResources().getStringArray(R.array.themes);
                theme = themes[arg2];
                Toast.makeText(NewFile.this, theme, Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                // TODO Auto-generated method stub

            }
        });
我通过将LayoutFlater代码更改为

LayoutInflater layoutInflater = LayoutInflater.from(MyActivity.this);
这修复了我的微调器错误,但现在对话框中没有任何文本视图显示。如何解决这两个问题

编辑

public void jqueryMobileDialog(){
AlertDialog.Builder customDialog=新建AlertDialog.Builder(此);
LayoutInflater LayoutInflater=context.getLayoutInflater();
视图=LayoutFlater.inflate(R.layout.jquery\u对话框,空);
final EditText idTxt=(EditText)view.findViewById(R.id.idName);
最终微调器themeSpinner=(微调器)视图
.findViewById(R.id.themeSpinner);
最终复选框headerChk=(复选框)view.findViewById(R.id.headerChk);
最终复选框footerChk=(复选框)view.findviewbyd(R.id.footerChk);
最终射线组组=(射线组)视图
.findViewById(R.id.jqmNavigation);
customDialog.setView(idTxt);
customDialog.setView(headerChk);
customDialog.setView(footerChk);
setOnItemSelectedListener(新的OnItemSelectedListener()){
@凌驾
已选择公共视图(AdapterView arg0、视图arg1、,
整数arg2,长arg3){
//TODO自动生成的方法存根
themes=getResources().getStringArray(R.array.themes);
主题=主题[arg2];
Toast.makeText(NewFile.this,theme,Toast.LENGTH_SHORT).show();
}
@凌驾
未选择公共无效(AdapterView arg0){
//TODO自动生成的方法存根
}
});

布局充气器需要来自一个有权绘制到屏幕的上下文。只有当前活动具有此权限。因此,调用getApplicationContext()。getLayoutInflater将永远无法工作-应用程序上下文没有权限。请改为使用当前活动的getLayoutInflater

还有两种情况会发生。一种是如果你弹出对话框太快(在你的活动有权显示之前)。我找到的唯一解决方案是向您自己发送一条消息,在发生这种情况时在100毫秒内重试,然后重试几次。例如,如果您尝试在onCreate中显示对话框,则会发生这种情况


另一种情况是当您的对话框试图在您的活动失去前景的同时显示时。没有解决方案,因为您不知道是否/何时将再次成为前景应用程序。在这里,您希望捕获并忽略。请注意,这也可能发生在旋转和其他终止并重新启动的配置更改周围该活动。

更改了我的布局升级代码,但现在一旦对话框试图显示,它就会崩溃。请参阅编辑。谢谢。
LayoutInflater layoutInflater = LayoutInflater.from(MyActivity.this);
public void jqueryMobileDialog() {
        AlertDialog.Builder customDialog = new AlertDialog.Builder(this);
        LayoutInflater layoutInflater = context.getLayoutInflater();
        View view = layoutInflater.inflate(R.layout.jquery_dialog, null);
        final EditText idTxt = (EditText) view.findViewById(R.id.idName);
        final Spinner themeSpinner = (Spinner) view
                .findViewById(R.id.themeSpinner);
        final CheckBox headerChk = (CheckBox) view.findViewById(R.id.headerChk);
        final CheckBox footerChk = (CheckBox) view.findViewById(R.id.footerChk);
        final RadioGroup group = (RadioGroup) view
                .findViewById(R.id.jqmNavigation);
        customDialog.setView(idTxt);
        customDialog.setView(headerChk);
        customDialog.setView(footerChk);
        themeSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1,
                    int arg2, long arg3) {
                // TODO Auto-generated method stub
                themes = getResources().getStringArray(R.array.themes);
                theme = themes[arg2];
                Toast.makeText(NewFile.this, theme, Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                // TODO Auto-generated method stub

            }
        });