0

I have a FragmentActivity and this is a tab bar. In first tab contain a fragment (Supportmapfragment). In second tab, also contain a fragment (Supportmapfragment). When i switch to second tab i can't do anything in second supportmapfragment, but when the screen lock and then unlock already can do. In this switch i hide de first fragment because i need to keep the state of first fragment.

This is possible, how can i do this. Thanks.

Pavel Dudka
  • 20,754
  • 7
  • 70
  • 83

1 Answers1

1

The solution i tried is while switching between activities of different tabs, remove the map on onpause() using removeView(), and again add it back using addView() on onResume().

The maps are inflated in Relative Layout, and its added and removed from that layout itself.

in onCreate() :

    setContentView(R.layout.rel_layout);
rel = (RelativeLayout)findViewById(R.id.rel);
LayoutInflater inflater = LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.map_layout, null);
rel.addView(view);

the onPause() and onResume() methods:

   @Override
   protected void onPause() 
   {
        rel.removeView(view);
    super.onPause();
   }

   @Override
   protected void onResume() 
   {
    if (view.getParent()!=rel)
        rel.addView(view);
    super.onResume();
   }
Early Bird
  • 76
  • 5