Hi i am using navigation drawer in my project and multiple fragments. in 1 of my fragment i have mapfragment which is added dynamically.
Now when that fragment loads it hides every other views in parent fragment.
and when i click on other fragment and comes back to fragment which contains map.. Map is not visible.
Following is my Fragment xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapActivity"
android:id="@+id/mapContainer">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button android:id="@+id/btnSearch"
android:text="Search"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
<EditText android:id="@+id/etSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Search"/>
</LinearLayout>
</FrameLayout>
and following is my java file for fragment.
public class MyRouteFragment extends Fragment {
public MyRouteFragment(){}
EditText etSearchValue;
private LatLng myPos;
UserData user;
View rootView;
GoogleMap mapView;
MapFragment mapFragment;
List<Marker> markers=new ArrayList<Marker>();
LocationsDataSource lDataSource;
public ProgressDialog pDialog=null;
FragmentManager mFragmentManager;
GoogleMapOptions options;
String address,TAG="MyMapTag";
Button btnSearch;
public static MyRouteFragment newInstance(LatLng position){
MyRouteFragment frag=new MyRouteFragment();
frag.myPos=position;
return frag;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
rootView = inflater.inflate(R.layout.fragment_my_route, container, false);
btnSearch=(Button) rootView.findViewById(R.id.btnSearch);
etSearchValue=(EditText) rootView.findViewById(R.id.etSearch);
mFragmentManager=getFragmentManager();
mapFragment=(MapFragment) mFragmentManager.findFragmentByTag(TAG);
if(mapFragment==null){
mapFragment=MapFragment.newInstance();
FragmentTransaction fragmentTransaction=mFragmentManager.beginTransaction();
fragmentTransaction.add(R.id.mapContainer,mapFragment,TAG);
fragmentTransaction.commit();
}
//btnSearch.getParent().bringChildToFront(btnSearch);
/*btnSearch.invalidate();
etSearchValue.invalidate();
btnSearch.bringToFront();
etSearchValue.invalidate();
btnSearch.invalidate();
*/
//container.removeView(btnSearch);
//container.addView(btnSearch);
//container.addView(etSearchValue);
//mapFragment=(MapFragment) mFragmentManager.findFragmentById(R.id.map);
mapView=mapFragment.getMap();
if(mapView!=null){
mapView.setPadding(0, 20, 0, 0);
mapView.setMyLocationEnabled(true);
}
btnSearch.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new getFormattedAddress().execute();
}
});
//btnSearch.bringToFront();
//etSearchValue.bringToFront();
return rootView;
}