Note that there are some explanatory texts on larger screens.

plurals
  1. POfindViewById returns null in fragment
    primarykey
    data
    text
    <p>I have problem using the findViewByID methond in a fragment.</p> <p>The spinner in <code>Spinner spinner = (Spinner) view.findViewById(R.id.tabsearchspinner_location);</code> is always null. Please see the code below.</p> <pre><code>public class FragmentTabSearch extends SherlockFragment implements OnItemSelectedListener { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View view = inflater.inflate(R.layout.fragment_tab_suggestions, container, false); Spinner spinner = (Spinner) view.findViewById(R.id.tabsearchspinner_location); ArrayAdapter&lt;CharSequence&gt; adapter = ArrayAdapter.createFromResource(this.getSherlockActivity(), R.array.spinner_location, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); return view; } @Override public void onItemSelected(IcsAdapterView&lt;?&gt; parent, View view, int position, long id) { // TODO Auto-generated method stub } @Override public void onNothingSelected(IcsAdapterView&lt;?&gt; parent) { // TODO Auto-generated method stub } </code></pre> <p>}</p> <p>The layout file is as below (ps: I have already declared the id/tabsearchspinner_location in the values/ids.xml file): <code>&lt;item type="id" name="tabsearchspinner_location"&gt;&lt;/item&gt;</code></p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" &gt; &lt;Spinner android:id="@id/tabsearchspinner_location" android:layout_width="wrap_content" android:layout_height="wrap_content" /&gt; &lt;ListView android:id="@id/tablistview_search" android:layout_width="match_parent" android:layout_height="wrap_content" &gt; &lt;/ListView&gt; </code></pre> <p></p> <p>Any help is appreciated!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload