にスピナーを移植:は、私は次のコードを使用してAlertDialogでスピナーを埋めるためにしようとしていますAlertDialog
ArrayAdapter<String> dataAdapter = new ArrayAdapter<>(this,
android.R.layout.simple_spinner_item, providersList);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
AlertDialog.Builder checkInDialog1 = new AlertDialog.Builder(this);
checkInDialog1.setView(R.layout.layout_checkin_items);
checkInDialog1.show();
AlertDialog builder = checkInDialog1.create();
Spinner checkInProviders = (Spinner) builder.findViewById(R.id.providers);
checkInProviders.setAdapter(dataAdapter);
しかしbuilder.findViewByIdはcheckInProvidersにnullを返しています。私のXMLで
:
<Spinner
android:id="@+id/providers"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
助けてください。ありがとう。
あなたはポップアップでただスピナーを必要としますか? –
ビューを拡張しようとしてください。 AlertDialog.Builder checkInDialog1 = new AlertDialog.Builder(this); ビューdialogView = View.inflate(this、R.layout.layout_checkin_items、null);checkInDialog1.setView(dialogView); SpinnerのcheckInProviders = dialogView.findViewById(R.id.providers); –