Reputation: 593
ERROR: FATAL EXCEPTION: main Process: groep2.project4, PID: 18507 java.lang.IllegalArgumentException: No view found for id 0x7f0d00a5 (groep2.project4:id/map) for fragment SupportMapFragment{b36c267 #0 id=0x7f0d00a5}
DrawerActivity.java
} else if (id == R.id.locatie) { fragment = fragLocatie;
if(!sMapFragment.isAdded()) {
sFragmentManager.beginTransaction().add(R.id.map, sMapFragment).commit();
}else{sFragmentManager.beginTransaction().show(sMapFragment).commit();}
Locatie.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
<FrameLayout
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"></FrameLayout>
</LinearLayout>
</RelativeLayout>
content_drawer.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:id="@+id/drawer_start"
tools:context="groep2.project4.DrawerActivity"
tools:showIn="@layout/app_bar_drawer"
android:background="#7EC580"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="23">
</FrameLayout>
</LinearLayout>
Correct me if im wrong but i think its because the map isnt a child of the drawer activity, but i ony want to display the map in the "locatie" fragment.
can anyone guide me in the right direction here? moving the maps to the content_drawer.xml makes it visible in all fragments, and i have absolutely no clue how to fix this
edit:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_drawer);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
sMapFragment = SupportMapFragment.newInstance();
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
// navigationView.setItemTextColor(ColorStateList.valueOf(Color.DKGRAY));
menucolormanager.HeadingCharts(navigationView.getMenu().findItem(R.id.categorie1),navigationView.getMenu().findItem(R.id.categorie2),navigationView.getMenu().findItem(R.id.categorie3), navigationView.getMenu().findItem(R.id.categorie4));
sMapFragment.getMapAsync(this);
}
public boolean onNavigationItemSelected(MenuItem item) {
android.support.v4.app.FragmentManager sFragmentManager = getSupportFragmentManager();
// Handle navigation view item clicks here.
int id = item.getItemId();
Fragment fragment;
if(sMapFragment.isAdded()){
sFragmentManager.beginTransaction().hide(sMapFragment).commit();
}
if (id == R.id.fietstrommels) {fragment = fragFietsTrommels;
} else if (id == R.id.diefstallen) { fragment = fragDiefstallen;
} else if (id == R.id.locatie) { fragment = fragLocatie;
if(!sMapFragment.isAdded()) {
sFragmentManager.beginTransaction().add(R.id.map, sMapFragment).commit();
}else{sFragmentManager.beginTransaction().show(sMapFragment).commit();}
} else if (id == R.id.route) { fragment = fragRoute;
} else if (id == R.id.kladblok) { fragment = fragKladblok;
} else {return false;}
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.drawer_start, fragment).commit();
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
Upvotes: 2
Views: 306
Reputation: 1921
Inside your Locatie fragment
class while adding SupportMapFragment
you have to use ChildFragmentManager
as fragmentManager because you are adding fragment inside a fragment. Below is the sample code:
FragmentManager sFragmentManager = getChildFragmentManager();
sFragmentManager.beginTransaction().replace(R.id.map, sMapFragment).commit()
Hope it works, let me know if you have trouble implementing the same.
Upvotes: 1