-1

I have two tabs.First tab is for map .Second tab is for list. And I tried to display the map on the first tab. But it has displayed only the layout [return inflater.inflate(R.layout.map_activity, container, false);] But instead of this I have one activity for map, i want to load that activity without losing tab ,inside the tab itself.Please help me

Visal Varghese
  • 436
  • 5
  • 14
  • Make It fragment and show that in tab. – Shree Krishna Mar 13 '16 at 05:15
  • Not like that. private void setupViewPager(ViewPager viewPager) { ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager()); adapter.addFragment(new MapFragment(), "Map View"); adapter.addFragment(new ListFragment(), "List View"); viewPager.setAdapter(adapter); } – Visal Varghese Mar 13 '16 at 05:20
  • Anywhere You only have a Context then you can start a Activity with new Intent and activity_name.class. – GiapLee Mar 13 '16 at 05:23
  • If i start an activity that will call new page. I do not want that.Inside that tab i want to start an activity.can anyone help me with some example – Visal Varghese Mar 13 '16 at 05:27
  • mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); mTabHost.setup(this, getSupportFragmentManager(), android.R.id.tabcontent); mTabHost.addTab( mTabHost.newTabSpec("tab1").setIndicator("Tab 1", null), FragmentTab.class, null); mTabHost.addTab( mTabHost.newTabSpec("tab2").setIndicator("Tab 2", null), FragmentTab.class, null); mTabHost.addTab( mTabHost.newTabSpec("tab3").setIndicator("Tab 3", null), FragmentTab.class, null); } can i add activity? – Visal Varghese Mar 13 '16 at 08:10

1 Answers1

0

As you told you want to show activity in fragment, Your tabs are fragments. I want to make clear that Fragment cant host Activity. Your Activty can have multiple fragments, but fragments cannot have fragments inside them. You don't have alternatives than making it Fragment if you really want to show it in tab. If you are trying to show something more in same tab so that you don't want to make it fill the entire screen and start a new Activity then there is options of Nested Fragments. You can show half screen as map and half as you want inside same tab.

Shree Krishna
  • 8,474
  • 6
  • 40
  • 68
  • add codes inside onCreateView to initialize map as you may did in Activity Don't just inflate the layout. Others are fine... – Shree Krishna Mar 13 '16 at 09:53
  • public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, GoogleMap.OnMarkerDragListener, GoogleMap.OnMapLongClickListener, View.OnClickListener{ these things are using on that activity – Visal Varghese Mar 13 '16 at 10:01
  • There is supportmapfragment for using it in fragments.. have a look [here](http://stackoverflow.com/questions/19353255/how-to-put-google-maps-v2-on-a-fragment-using-viewpager).. you will get more knowledge.. – Shree Krishna Mar 13 '16 at 10:24
  • SupportMapFragment mapFragment = (SupportMapFragment) this.getChildFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); i got the above error – Visal Varghese Mar 13 '16 at 10:43