Setting spinners in fragment

后端 未结 1 762
失恋的感觉
失恋的感觉 2021-02-04 12:02

I am trying to set the values for my spinner from a string Array in one of my fragments in the onCreateView in my public final class Manual extends Fragment<

相关标签:
1条回答
  • 2021-02-04 12:44

    The problem was I was returning a new view, not the one I set. I had to return v; and it worked fine.

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    
        View v = inflater.inflate(R.layout.manual, container, false);
    
        String [] values = 
            {"Time at Residence","Under 6 months","6-12 months","1-2 years","2-4 years","4-8 years","8-15 years","Over 15 years",};
        Spinner spinner = (Spinner) v.findViewById(R.id.spinner1);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getActivity(), android.R.layout.simple_spinner_item, values);
        adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
        spinner.setAdapter(adapter);
    
        return v;
    
    }
    
    0 讨论(0)
提交回复
热议问题