android - How do you get the current fragment's ID? -


i've created viewpager 8 fragments use same xml layout. however, want different fragments use different content. need id of whatever fragment can load specific content onto fragment.

i've tried

extras.putint(globals.key_category_position, position); fragment.setarguments(extras); 

in getitem(int position) method on fragmentpageradapter.

then, position of fragment in fragment class. when this, go 0 7 when print out position of each fragment of them increment 7 become same fragment.

is there other way id each fragment?

here quite nice example:

https://github.com/jakewharton/actionbarsherlock/blob/master/actionbarsherlock-samples/fragments/src/com/actionbarsherlock/sample/fragments/fragmentpagersupport.java

when creating fragment:

        bundle args = new bundle();         args.putint("num", num);         f.setarguments(args); 

and in fragment:

    @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         mnum = getarguments() != null ? getarguments().getint("num") : 1;     } 

Comments