java - Android - Fragment findViewById() always null? -


Yes, I know there are so many similar questions to this one, but unlike others, my onCreateView () the footage inflates for the fragment. When I do not use findViewById () , everything works unnecessarily and works as expected of my app (except for the functionality I want to get in findViewById () .

here is my code:

  @Override public view onCreateView (LayoutInflater p_inflater, ViewGroup p_container, bundled p_prev_state) {return p_inflater.inflate (R.layout.fragment_main, p_container, wrong);}  

Whenever I want to use a ListView within my layout, I do this:

  private ListView getListView () {return (ListView). getView () findViewById (R.id.main_events);}  

But it is always null Why Me fragment_main.xml appears so:.?

<> & lt East; RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/ android "xmlns: device =" Http://schemaskandroidkcom/tools "Android: Layout_width =" match_parent "Android: Layout_height =" Match_parent "android: background =" @ color / white "Tools manual =" me. K.cal.Ma Inactive $ Placeholder Fragment "& gt; & Lt; ListView Android: Android: Android: layout_width = "fill_parent" android: layout_height = "fill_parent" Android: dividerHeight = "1dp" android: divider = "@color / background_color" / & gt; & Lt; / RelativeLayout & gt;

Increasing your view and below to get the ID Use code to list view.

  Kriattiwu (Leautinfletr Inflatr, View Group container, bundle saved Instensstet) on public view {See _view = Infliattr. In flat (r. Letafrmment 1, container, false); ListView _list = (List View) _view.findViewById (R.id.main_events); Return _view; }  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -