Home Ask Login Register

Developers Planet

Your answer is one click away!

Louis B February 2016

Can't set the adapter of a Spinner into a Fragment

I got this error while trying to fill the items of a snipper with the elements of an array.

This is the error I have:

02-06 21:00:58.519 7493-7493/com.dogsupdate.dogsupdate E/dalvikvm: Could not find class 'android.widget.ThemedSpinnerAdapter', referenced from method android.support.v7.widget.AppCompatSpinner$DropDownAdapter.

String[] lang = {"es","en"};

final View layout=inflater.inflate(
    R.layout.fragment_fragment_settings, container, false);

Spinner lang = (Spinner) layout.findViewById(R.id.setLang);

lang.setAdapter(
  new ArrayAdapter<String>(
     getActivity().getApplicationContext(),
     android.R.layout.simple_spinner_item , 
     idiomas));

return inflater.inflate(
  R.layout.fragment_fragment_settings, container, false);

Any idea? Thanks in advance.

Answers


ELITE February 2016

What you are doing is getting layout from LayoutInflater

final View layout=inflater.inflate(
R.layout.fragment_fragment_settings, container, false);

Finding the Spinner from the layout

Spinner lang = (Spinner) layout.findViewById(R.id.setLang);

Setting ArrayAdapter to Spinner

lang.setAdapter(new ArrayAdapter<String>(getActivity().getApplicationContext(), android.R.layout.simple_spinner_item ,  idiomas));

and returning the new layout from inflating again

return inflater.inflate(R.layout.fragment_fragment_settings, container, false);

so change the return statement by

return layout;

and it'll work perfectly...

Post Status

Asked in February 2016
Viewed 1,399 times
Voted 6
Answered 1 times

Search




Leave an answer


Quote of the day: live life