Android - getSupportFragmentManager returns null -
i trying specific instance of fragment using it's tag, using viewpager, makes things difficult. used:
public fragment getfragmentbyposition(int pos) { string tag = "android:switcher:" + r.id.pager + ":" + pos; fragmentmanager fragmentmanager = this.getsupportfragmentmanager(); fragment fragment = fragmentmanager.findfragmentbytag(tag); return fragment; }
to find fragment, getsupportfragmentmanager returning null.
the above method in activity, outside of viewpager adapter class, , lost here. highly appreciated, thanks!
you can use smartviewpager here https://gist.github.com/jacek-marchwicki/d6320ba9a910c514424d
extend view pager class , fragment using getactivefragment method. can change implementation of method fragment tag name.
public fragment getactivefragment(string name) { final fragment fragmentbytag = fragmentmanager.findfragmentbytag(name); if (fragmentbytag == null) { final bytearrayoutputstream outputstream = new bytearrayoutputstream(); fragmentmanager.dump("", null, new printwriter(outputstream, true), null); final string s = new string(outputstream.tobytearray(), charsets.utf_8); throw new illegalstateexception("could not find fragment via hacky way.\n" + "we looking name: " + name + "\n" + "fragment name not exists, or hack stopped working.\n" + "current fragment manager dump is: " + s); } return fragmentbytag; }
Comments
Post a Comment