スピナーとの対話があります。
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 に TextView が表示されなくなりました。両方の問題を解決するにはどうすればよいですか?
編集
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
}
});