I am trying to get a selected view of my spinner but it is returning null as all the time.
spinner.getSelectedView()
Any idea?
I am trying to get a selected view of my spinner but it is returning null as all the time.
spinner.getSelectedView()
Any idea?
Even after setting the view spinner.getSelectedView()
was returning null
for me.
As a workaround, I used the following code which worked for me and returned the correct view for some reason.
new Handler().post(() -> ((TextView)mVehicleView.getSelectedView()).setTextColor(context.getColor(R.color.gray2)));
If someone can explain why this happened, it would be great.
Posting this incase it happens to someone else.
You don't need the view, do you? I think this is what you want:
Spinner s = (Spinner) findViewById(R.id.spinner);
String text = s.getSelectedItem().toString();
Yes, in my case it was timing issue as the getSelectedView() was called before setting selection. That explains why I was getting the view as null.