我有一个与微调器的对话。
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
}
});
当我单击微调器时,我收到错误
04-25 18:01:56.299: E/AndroidRuntime(21639331): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
我通过将 LayoutInflater 代码更改为
LayoutInflater layoutInflater = LayoutInflater.from(MyActivity.this);
它修复了我的 Spinner 错误,但现在我的 Dialog 中的 TextViews 都没有出现。如何解决这两个问题?
编辑
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
}
});