I am having a spinner that should be filled with strings.But can not use binding.mySpinner
to set adapter.
The Goal is to have two spinners first is with two country USA and CANADA so when user click on Usa second spinner should list all states.Same thing for Canada.I managed to find out what country is clicked and i stored that value in String.I wanted to use simple If/else statement but do not know how to fill second spinner.
my xml:`
<Spinner
android:id="@+id/states_spinner"
style="@style/Widget.AppCompat.DropDownItem.Spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp"
app:layout_constraintBottom_toTopOf="@+id/submit_BTN"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/states_TV" />
`
and my ViewModel:
public AdapterView.OnItemSelectedListener countryListener = new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Object item = parent.getItemAtPosition(position).toString();
switch (position){
case 0:
billingInfo.setCountry("Usa");
selectedCountry = billingInfo.getCountry();
List<String> listUsa = new ArrayList<String>(Arrays.asList(SpinnerEntriesUtils.usaArray));
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
SuccessPlanApplication.getContext(), android.R.layout.simple_spinner_item,listUsa );
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
break;
case 1:
billingInfo.setCountry("Canada");
selectedCountry = billingInfo.getCountry();
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
};