android - Managing Fragments inside tabs -


i'm creating simple activity, contains 2 tabs. i'm following documentation, i'm using fragment. in activity there 2 tabs. first 1 map (mapfragment), while second simple list (listfragment)

all works good, problem can't manage correctly map.

in ontabselected callback have use following code:

public void ontabselected(tab tab, fragmenttransaction ft) {     if (mfragment == null) {         mfragment = fragment.instantiate(mactivity, mclass.getname(), margs);         ft.add(android.r.id.content, mfragment, mtag);     } else {         ft.attach(mfragment);          if(mtag.comparetoignorecase("map")==0)             setupmapifneeded((mapfragment)mfragment);      } } 

where map tag of first activity , mthod setupmapifneeded is:

private static void setupmapifneeded(mapfragment mmapfragment) {     // null check confirm have not instantiated map.     if (mmap == null) {         mmap = mmapfragment.getmap();         // check if successful in obtaining map.         if (mmap != null) {             mmap.addmarker(new markeroptions().position(new latlng(0, 0)).title("marker"));         }     } } 

so marker added in map if select tab.

the questione is: how can modify code performing addmarker action when activity started (without pressing explicitly first tab)?

i have solved adding code:

@override protected void onresume() {     // todo auto-generated method stub     super.onresume();      fragmentmanager fm = getfragmentmanager();     fragment f = fm.findfragmentbytag("map");     if(f!= null && f.isadded())         setupmapifneeded((mapfragment)f); } 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -