findViewById returns null in fragment

前端 未结 2 1567
温柔的废话
温柔的废话 2021-01-16 11:10

I have problem using the findViewByID methond in a fragment.

The spinner in Spinner spinner = (Spinner) view.findViewById(R.id.tabsearchspinner_location);

2条回答
  •  伪装坚强ぢ
    2021-01-16 11:35

    Inflate your View without a ViewGroup, as it's simply inside your FragmentActivity:

    View view = inflater.inflate(R.layout.fragment_tab_suggestions, null);
    

    And the way IDs are added inside the XML layout files is like this:

    android:id="@+id/tabsearchspinner_location"
    

    As you can see, you're missing the +

提交回复
热议问题