In my android app I use 3 different spinners, but one of them won’t show my selection.
When I click on it I can see all the item in it, but when I select one of them nothing shows in the spinner itself, and the app goes on as if I didn’t select anything.
The problem might be that I’m filling items in my spinner after selecting an item in another spinner, but the spinner shows items I would expect it to have when clicking on it, it just doesn’t select any of them when it should.
Spinner that fills the other one (and that works fine):
ArrayAdapter<String> adapter= new ArrayAdapter<>(v.getContext(), android.R.layout.simple_spinner_item, arraySpinner);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(v.getContext(), arraySpinner.get(position),Toast.LENGTH_SHORT).show();
dArray.clear();
for(x=0; x< mValAtts.size();x++){
if (mValAtts.get(x).getmVId()==mFibers.get(spinner.getSelectedItemPosition()).getmId()){
dArray.add(mValAtts.get(x).getmWLen());
}
}
valne.setSelection(0);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
The problematic spinner:
ArrayAdapter<Double> adapter2= new ArrayAdapter<>(v.getContext(), android.R.layout.simple_spinner_item, dArray);
ad1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
valne.setAdapter(ad1);
valne.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(v.getContext(), Double.toString(dArray.get(position)),Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
I should also mention that I set the adapter for the second spinner before the code for the EventListener of the first spinner.
I was thinking that maybe it wasn’t parsing double to string correctly in the second spinner, but if the data is a string it still doesn’t change anything.
I tried changing the width and height to wrap content, but it’s the same, the problem is that nothing is selected as far as the app is concerned.
Help needed, thanks!