I am trying to open an mapsfragment from another fragement which has a list of items. When I do that I get:
No view found for id 0x7f0a001a (com.ylg.main:id/map) for fragment Maps{435e2398 #2 id=0x7f0a001a}
what could be wrong here.
Maps.class:
public class Maps extends Fragment implements GoogleMap.OnMyLocationChangeListener { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (rootView != null) { ViewGroup parent = (ViewGroup) rootView.getParent(); if (parent != null) parent.removeView(rootView); } try { rootView = inflater.inflate(R.layout.activity_maps, container, false); } catch (InflateException e) { /* map is already there, just return view as it is */ } fa = getActivity(); if (initMap()) { gps = new GPSTracker(fa); curlat = gps.getLatitude(); curlong = gps.getLongitude(); gps.stopUsingGPS(); //Get the ZOOM working for given location. } else { Toast.makeText(getActivity().getApplicationContext(),"Sorry! Map not available!", Toast.LENGTH_SHORT).show(); } return rootView; } private boolean initMap() { if (googleMap == null) { SupportMapFragment mapFrag = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map)); googleMap = mapFrag.getMap(); googleMap.setTrafficEnabled(true); googleMap.setMyLocationEnabled(true); googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); googleMap.setOnMyLocationChangeListener(this); } return (googleMap != null); } }
My activity_maps.XML looks like this:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/relativeLayoutforMap" android:layout_width="match_parent" android:layout_height="match_parent" > <fragment android:id="@+id/map" android:name="com.google.android.gms.maps.MapFragment" android:layout_width="match_parent" android:layout_height="match_parent" /> </RelativeLayout>
from: Friends.class
I have list of items in this class on Item Click I am trying to open the maps fragement.
public class Friends extends Fragment { View rootView = inflater.inflate(R.layout.activity_friends, container, false); list = (ListView) rootView.findViewById(R.id.friends_list); list.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { android.support.v4.app.FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); Maps fragment = new Maps(); fragmentTransaction.replace(R.id.map, fragment); fragmentTransaction.commit(); } }); return rootView; }
Can somebody help me fix this?
Thanks!