android - Display google map with fragment/activity -


i trying display google maps, havent used fragments suspect problem is..

my java class locatormap.java is:

public class locatormap extends fragment {      mapview m;      @override     public view oncreateview(layoutinflater inflater, viewgroup container,              bundle savedinstancestate) {         // inflat , return layout         view v = inflater.inflate(r.layout.activity_locator_map, container, false);         m = (mapview) v.findviewbyid(r.id.mapview);         m.oncreate(savedinstancestate);          return v;     }      @override     public void onresume() {         super.onresume();         m.onresume();     }      @override     public void onpause() {         super.onpause();         m.onpause();     }      @override     public void ondestroy() {         super.ondestroy();         m.ondestroy();     }      @override     public void onlowmemory() {         super.onlowmemory();         m.onlowmemory();     } 

and activity xml :

<?xml version="1.0" encoding="utf-8"?> <com.google.android.gms.maps.mapview     xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:id="@+id/mapview" /> 

and trying present view this:

intent intent = new intent(getapplicationcontext(), locatormap.class);     startactivity(intent);   

when get:

unable instantiate activity componentinfo{my package name.locatormap} 

and cannot cast android.app.activity

what doing wrong?

public class locatormap extends fragment { 

its not activity class , can't use

intent intent = new intent(getapplicationcontext(), locatormap.class); startactivity(intent);  

what need container in activity layout add fragment.

more info

http://developer.android.com/guide/components/fragments.html

generally container framelayout. add framelayout id fragment_container in activity xml , have following code in activity class.

locatormap  newfragment = new locatormap() ; fragmenttransaction transaction = getsupportfragmentmanager().begintransaction(); transaction.replace(r.id.fragment_container, newfragment); transaction.addtobackstack(null); // if want fragment added backstack transaction.commit(); 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -