简体   繁体   中英

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.

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM