android - findFragmentById return null -


When I call fragmentiIID () with my piece ID, then it is empty. Let me show you the code

activity_main.xml

  & lt ;? Xml version = "1.0" encoding = "UTF-8" & gt; & Lt; LinearLayout xmlns: android = "Http://schemaskandroidkcom/apk/res/android" android: orientation = "vertical" android: Layout_width = "Fill_parent" Android: layout_height = "fill_parent" & gt; & Lt; Fragment android: name = "com.madduck.test.app.fragment.MainFragment" android: id = "@ + id / main_fragment" Android: layout_width = "match_parent" android: layout_height = "match_parent" /> & Lt; Fragment android: name = "com.madduck.test.app.fragment.LoginFragment" Android: id = "@ + id / login_fragment" Android: layout_width = "match_parent" Android: layout_height = "match_parent" /> & Lt; / LinearLayout & gt;  

Main activity. Java

  private constant final integer LOGIN = 0; Private static final end MAIN = 1; Private Stable FINAL INC. FRAGMENT_COUNT = MAIN +1; Personal piece [] Pieces = new piece [FRAGMENT_COUNT] Creates a protected void (bundle saved instenstate) {super. Contents (Saved Instantstate); SetContentView (R.layout.activity_main); Fragment Manager FM = Millennial Support Fragmentation Manager (); Pieces [LOGIN] = fm.findFragmentById (R.id.login_fragment); Pieces [Main] = fm.findFragmentById (R.id.main_fragment); Piece transaction transaction = fm.beginTransaction (); For (fragment f: pieces) {if (f! = Null) transaction.hide (f); Other logs (Tag, "???"); } Transaction.commit (); }  

This is the thing when I call fm.findFragmentById (R.id.login_fragment); I get blank, but when I call fm.findFragmentById (R.id.main_fragment); I get a piece.

The answer is completely alright but it can help someone in my case I have a There was a piece inside the piece and I was getting the wrong piece manager. I just have to call:

getChildFragmentManager ()

and then find the piece in general:

  Fm .findragmentById (R.id.fragment)  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

lua - HowTo create a fuel bar -