I have seen many related questions but I can not spot where I am doing it wrong. I appreciate if anyone can help me. When I add only one MapView to the LinearLayout, map is working fine. But when I try to add one button or textView or anything in the layout it crashes in run time!
I have three separate fragments
. First one is called FragmentA.java and Fragment_a.xml
Here is Fragment_a.xml file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.maps.MapView android:id="@+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<Button android:id="@+id/googlemaps_select_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Select"
/>
</RelativeLayout>
And here is
FragmentA.java
I am not sure if
View v = inflater.inflate(R.layout.fragment_a, container, false);
is correct. fragment_a, as I said is the name of the fragment which contain complete view:
public class FragmentA extends Fragment {
MapView mapView;
GoogleMap map;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_a, container, false);
// Gets the MapView from the XML layout and creates it
mapView = (MapView) v.findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
// Gets to GoogleMap from the MapView and does initialization stuff
map = mapView.getMap();
map.getUiSettings().setMyLocationButtonEnabled(false);
map.setMyLocationEnabled(true);
MapsInitializer.initialize(this.getActivity());
// Updates the location and zoom of the MapView
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(43.1, -87.9), 10);
map.animateCamera(cameraUpdate);
return v;
}
@Override
public void onResume() {
mapView.onResume();
super.onResume();
}
@Override
public void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
I got the error which says, inflate exception binary xml file line #10 error inflating class fragment.
As I said I have seen many example such as this which was accepted answer but did not work for me: I am not sure why I am not using Layout base
in my above code in following xml file. which is strange.
<RelativeLayout
xmlns:android="http://ift.tt/nIICcg"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/base">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:id="@+id/editText"
>
</EditText>
<LinearLayout
android:id="@+id/linearLayout1"
android:gravity="bottom"
android:layout_width="fill_parent"
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_alignParentBottom="true">
<Button
android:text="Cancel"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"></Button>
<Button
android:text="Confirm"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"></Button>
</LinearLayout>
<com.google.android.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="0HD__0DaIgzDb8nHjJsuggkHlW1MofMwg-xVCpA"
android:layout_below="@+id/editText"
android:layout_above="@+id/linearLayout1"/>
</RelativeLayout>
Finally as I said this is working fine for me with no problem but when I add another element it fails:
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:tools="http://ift.tt/LrGmb4"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<com.google.android.gms.maps.MapView android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
As you can see in second one, I need a textEdit on top then map and down is two buttons. Thanks in advance.
No comments:
Post a Comment