アクティビティの開始時にスピナーを使用してAlertDialogを作成しようとしています。アクティビティのonCreate()メソッド内に次のコードがあります。
AlertDialog.Builder builder = new AlertDialog.Builder(this);
AlertDialog alertDialog;
Context mContext = getApplicationContext();
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_dialog,
(ViewGroup) findViewById(R.id.layout_root));
Spinner spinner = (Spinner) layout.findViewById(R.id.spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.num_players_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
builder = new AlertDialog.Builder(mContext);
alertDialog = builder.create();
alertDialog.show();
この力は毎回閉じます。次のコードを使用して、アクティビティの開始時に簡単なAlertDialogを正常に作成しました。
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Stackoverflow!").create().show();
誰かが私を正しい方向に向けてくれたら幸いです。