-1

I've checked other posts having this problem and they said use <merge> instead of <include> but when i use <merge> it shows red in my fragment.xml file, there is no such tag. How can i solve this error?

In my fragment.xml:

<androidx.coordinatorlayout.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <include layout="@layout/product_variation_bottom_sheet" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

In my Fragment.kt:

var view = inflater.inflate(R.layout.bottom_sheet, container, false)
bottomSheetBehavior = BottomSheetBehavior.from(view.findViewById(R.id.bottomSheet))

In my bottom_sheet.xml:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/productVariationBottomSheet"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_behavior="@string/bottom_sheet_behavior"
    app:behavior_peekHeight="0sp"
    app:behavior_hideable="true"
    android:background="#00000000"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    //some other views
</LinearLayout>
AhChing11
  • 125
  • 1
  • 3
  • 15
  • `` tags would go in the inner layout, not in place of the `` tag. That's not your problem, though. The `` with the `BottomSheetBehavior` has ID `productVariationBottomSheet`, but you're looking for something else: `BottomSheetBehavior.from(view.findViewById(R.id.bottomSheet))`. – Mike M. Jan 14 '22 at 13:50

2 Answers2

0

You must have parent layout as CoordinatorLayout. You put the CoordinatorLayout where you place the container. The container must be under the CoordinatorLayout.

M Azam Khan
  • 302
  • 3
  • 15
  • Yes the Container is LinearLayout, then i included it with `` in my fragment and the `` tag is right under CoordinatorLayout. In activity, it works fine by just calling `findViewById()`, but if in fragment I have to use layoutInflater to get the layout, that's where the error happens – AhChing11 Jan 14 '22 at 11:40
  • add CoordinatorLayout instead of LinnearLayout...if my answer is helpful please rate me – M Azam Khan Jan 14 '22 at 13:48
  • I tried moving LinearLayout one level lower, then make the root layout to CoordinatorLayout, and it shows BootomSheetBehaviour.from() requires LinearLayout. Then i put the bottom_sheet_behavior to the LinearLayout, one level below CoordinatorLayout, and other problems occured. – AhChing11 Jan 14 '22 at 14:00
0

Couldn't find any solution to solve it, so i stopped using <include> and just put all the BottomSheet's layout code into my fragment.xml altogether. Then access the BottomSheet layout directly using viewBinding. This way, it works. Any other solution that works, feel free to share your solution.

AhChing11
  • 125
  • 1
  • 3
  • 15