android - How to replace a fragment by itself on MarkerClick GoogleMap -
hello know how can replace fragment when click on same marker on googlemap. when click first time, fragment appears when click second time on it, app crash.
this fragment :
public class infowindowfragment extends fragment { public infowindowfragment() {} @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view v = inflater.inflate(r.layout.fragment_info_window, container, false); return v; }
}
this fragment declaration :
fragment fragment = new infowindowfragment(); private final fragmentmanager fragmentmanager = getsupportfragmentmanager(); private final fragmenttransaction fragmenttransaction = fragmentmanager.begintransaction();
this onmarkerclick function :
@override public boolean onmarkerclick(marker marker) { if (marker.equals(franprixmap)) { fragmenttransaction.replace(r.id.infowindow, fragment); fragmenttransaction.addtobackstack(null); fragmenttransaction.commit(); } return true; }
this marker :
franprixmap = map.addmarker(new markeroptions() .icon(bitmapdescriptorfactory.fromresource(r.drawable.logo_franprix2)) .position(logo_franprix3);
this main layout :
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <fragment android:id="@+id/map" class="com.google.android.gms.maps.supportmapfragment" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignparentbottom="true"/> <relativelayout android:id="@+id/infowindow" android:layout_width="match_parent" android:layout_height="150dp" android:layout_alignparentbottom="true"> </relativelayout>
this fragment's layout :
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="150dp"> <imageview android:id="@+id/imageview" android:layout_width="200dp" android:layout_height="200dp" android:src="@drawable/image2" /> <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margintop="10dp" android:layout_weight="50" android:orientation="vertical"> <textview android:id="@+id/txtname" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginbottom="10dp" android:text="text" android:textappearance="?android:attr/textappearancemedium" android:textcolor="#000"/> <textview android:text="35 avenue de flandre" android:textappearance="?android:attr/textappearancemedium" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/txtaddress" android:layout_marginbottom="10dp" android:textcolor="#000"/> <textview android:id="@+id/txthours" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginbottom="10dp" android:text="10h - 20h" android:textappearance="?android:attr/textappearancemedium" android:textcolor="#000" /> </linearlayout>
i have tried lot of solutions, nothing work. thank !
Comments
Post a Comment