I have an application composed by a pageviewer with 3 fragments. one of this fragment is a map and the idea is to show a bottosheetbehaviuor on map marker click.
here is my layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
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"
tools:context="com.myapp.android.activities.MainActivity"
android:nestedScrollingEnabled="true">
<RelativeLayout
android:id="@+id/rlMap"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"
tools:layout="@layout/content_main"
/>
<androidx.core.widget.NestedScrollView
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="@android:color/white"
app:behavior_hideable="true"
app:behavior_peekHeight="155dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<TextView
android:id="@+id/bottom_sheet_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:textSize="16sp" />
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
then... during oncreate I setup both view pager , map and bottom sheet
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
bottomSheetText = findViewById(R.id.bottom_sheet_text);
View bottomSheet = findViewById(R.id.bottom_sheet);
mBottomSheetBehaviour = BottomSheetBehavior.from(bottomSheet);
mBottomSheetBehaviour.setState(BottomSheetBehavior.STATE_HIDDEN);
ViewPager viewPager = findViewById(R.id.viewpager);
setupViewPager(viewPager);
TabLayout tabLayout = findViewById(R.id.tablayout);
tabLayout.setupWithViewPager(viewPager);
the viewpager and map via a call to a a func
private void setupViewPager(ViewPager viewPager) {
Log.d(TAG, "setupViewPager");
ViewPagerAdapter adapter = new ViewPagerAdapter
(getSupportFragmentManager());
createUpMap();
adapter.addFragment(mapFrag, "Map");
//TEMP
adapter.addFragment(new SupportMapFragment(), "List");
adapter.addFragment(new SupportMapFragment(), "Session");
viewPager.setAdapter(adapter);
private void createUpMap() {
Log.d(TAG, "createUpMap");
if (mapFrag == null) {
Log.d(TAG, "mapFrag is null, creation of map...");
mapFrag = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.rlMap);
mapFrag = new SupportMapFragment();
lastly, I ovveride marker click to display the bottomsheet:
mMap.setOnMarkerClickListener(marker -> {
Log.e(TAG, "POINT HAS BEEEN CLICKED status: " + mBottomSheetBehaviour.getState());
if (mBottomSheetBehaviour.getState() == BottomSheetBehavior.STATE_EXPANDED) {
bottomSheetText.setText(marker.getTag().toString());
mBottomSheetBehaviour.setPeekHeight(200);
mBottomSheetBehaviour.setState(BottomSheetBehavior.STATE_EXPANDED);
I launch the application, click on the marker and in the log in log I can see correct state ( I'm printing it as you see from calls) but absolutely no way to see it on screen. I 'm little out of ideas as there's no error and i don't know how to move.
Someone can move me in the right direction ?
many thanks!