android - findViewById returns null in fragment -
i have problem using findviewbyid methond in fragment.
the spinner in spinner spinner = (spinner) view.findviewbyid(r.id.tabsearchspinner_location);
null. please see code below.
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<charsequence> 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<?> parent, view view, int position, long id) { // todo auto-generated method stub } @override public void onnothingselected(icsadapterview<?> parent) { // todo auto-generated method stub }
}
the layout file below (ps: have declared id/tabsearchspinner_location in values/ids.xml file): <item type="id" name="tabsearchspinner_location"></item>
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <spinner android:id="@id/tabsearchspinner_location" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <listview android:id="@id/tablistview_search" android:layout_width="match_parent" android:layout_height="wrap_content" > </listview>
any appreciated!
inflate view
without viewgroup
, it's inside fragmentactivity:
view view = inflater.inflate(r.layout.fragment_tab_suggestions, null);
and way ids added inside xml layout files this:
android:id="@+id/tabsearchspinner_location"
as can see, you're missing +
Comments
Post a Comment