android - Interact with Button from another layout in SupportMapFragment -


i know how hide/show floatingactionbutton when clicking marker in map.

here's maps code:

public class mapsactivity extends supportmapfragment implements  onmapreadycallback, googlemap.onmapclicklistener,  googlemap.onmarkerclicklistener, googlemap.oninfowindowclicklistener {  private static final string tag = "maps"; private googlemap mmap; private locationmanager locationmanager; private arraylist<latlng> latlngs = new arraylist<>(); private markeroptions markeroptions = new markeroptions(); private marker markern; private marker markero;  @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     getmapasync(this); }  @override public void onmapready(googlemap googlemap) {      try {         criteria criteria = new criteria();         locationmanager = (locationmanager)  getactivity().getsystemservice(context.location_service);         mmap = googlemap;         mmap.setonmapclicklistener(this);         mmap.setonmarkerclicklistener(this);         mmap.getuisettings().setzoomcontrolsenabled(true);         mmap.getuisettings().setmaptoolbarenabled(false);         mmap.setmylocationenabled(true);         location location =  locationmanager.getlastknownlocation(locationmanager                 .getbestprovider(criteria, false));         double latitude = location.getlatitude();         double longitude = location.getlongitude();         latlng sydney = new latlng(latitude, longitude);         mmap.movecamera(cameraupdatefactory.newlatlngzoom(sydney, 15.0f));         mmap.setoninfowindowclicklistener(this);     } catch (securityexception ex) {         log.e(tag, "error", ex);         requestpermissions(new string[] {manifest.permission.access_fine_location},                 1);     } catch (exception e) {         system.out.println(e);     }      try {         // customise styling of base map using json object defined         // in raw resource file.         boolean success = mmap.setmapstyle(                 mapstyleoptions.loadrawresourcestyle(                         getcontext(), r.raw.style_json));          if (!success) {             log.e("mapsactivityraw", "style parsing failed.");         }     } catch (resources.notfoundexception e) {         log.e("mapsactivityraw", "can't find style.", e);     }      latlngs.add(new latlng(-22.978608, -49.869901));     (latlng point : latlngs) {         markeroptions.position(point);         markeroptions.title("local");         markeroptions.snippet("info");         markero = mmap.addmarker(markeroptions);     } }  @override public void onmapclick(latlng latlng) {     mmap.clear();     markeroptions.position(latlng);      markeroptions.title("deseja cadastrar este local?");     markeroptions.snippet("pressione aqui");     markern = mmap.addmarker(markeroptions);     mmap.animatecamera(cameraupdatefactory.newlatlngzoom(latlng, 17.0f));     toast.maketext(getcontext(), "coord: " + latlng.tostring(),  toast.length_long).show(); }  @override public void onrequestpermissionsresult(int requestcode, string  permissions[], int[] grantresults) {     switch (requestcode) {         case 1: {             // if request cancelled, result arrays empty.             if (grantresults.length > 0                     && grantresults[0] == packagemanager.permission_granted)  {              } else {                 // permission denied, boo! disable                 // functionality depends on permission.             }             return;         }         // other 'case' lines check other         // permissions app might request     } }  @override public void oninfowindowclick(marker marker) {     if (marker.equals(markern)) {         toast.maketext(getcontext(), "clique 2", toast.length_long).show();     } else {      } }  @override public boolean onmarkerclick(marker marker) {     if (marker.equals(markern)) {         toast.maketext(getcontext(), "clique 1", toast.length_long).show();     } else {         toast.maketext(getcontext(), "abrir informações",  toast.length_long).show();     }     return false; } } 

and that's xml want interact:

<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.coordinatorlayout  xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.alan.unigeo.mainactivity">  <android.support.design.widget.appbarlayout     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:theme="@style/apptheme.appbaroverlay">      <android.support.v7.widget.toolbar         android:id="@+id/toolbar"         android:layout_width="match_parent"         android:layout_height="?android:attr/actionbarsize"         android:background="?attr/colorprimary"         app:popuptheme="@style/apptheme.popupoverlay" />  </android.support.design.widget.appbarlayout>  <include layout="@layout/content_main" />  <android.support.design.widget.floatingactionbutton     android:id="@+id/fab"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_gravity="bottom|end"     android:layout_margin="@dimen/fab_margin"     app:srccompat="@android:drawable/ic_dialog_email" />  </android.support.design.widget.coordinatorlayout> 

i've tryed looking examples alike situation failed. maps inside fragment of layout, , floatingactionbutton placed in layout "above" previous one. don't know if need show other code guys, if needed, ask it.

i have feature in program.

if not want show it, use code:

@override public void onviewcreated(view view, @nullable bundle savedinstancestate) {     super.onviewcreated(view, savedinstancestate);     ((floatingactionbutton) getview().getrootview().findviewbyid(r.id.fab)).hide(); }  @override public void ondestroyview() {     super.ondestroyview();     ((floatingactionbutton) getview().getrootview().findviewbyid(r.id.fab)).show(); } 

if want show it, switch .show() , .hide().


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -