BottomSheetDialog setOnClickListener not firing

Viewed 394

I am having issues firing the onClick method of the setOnClickListener of the BottomSheetDialog menu.

This is the xml fragment layout or the BottomSheetDialog

<?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"
    android:id="@+id/fragment_grocery_menu_bottom"
    android:layout_width="match_parent"
    android:layout_height="180dp"
    android:background="#ffffff"
    android:orientation="vertical"
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior">

    <LinearLayout
        android:id="@+id/fragment_grocery_bottom_sheet_search"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:clickable="true"
        android:descendantFocusability="blocksDescendants"
        android:focusable="true"
        android:foreground="?android:attr/selectableItemBackground"
        android:orientation="horizontal"
        android:padding="16dp">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:clickable="false"
            android:focusable="false"
            android:focusableInTouchMode="false"
            app:srcCompat="@drawable/ic_search_black_24dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="16dp"
            android:clickable="false"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:text="Search Item" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/fragment_grocery_bottom_sheet_got"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:clickable="true"
        android:descendantFocusability="blocksDescendants"
        android:focusable="true"
        android:foreground="?android:attr/selectableItemBackground"
        android:orientation="horizontal"
        android:padding="16dp">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:clickable="false"
            android:focusable="false"
            android:focusableInTouchMode="false"
            app:srcCompat="@drawable/ic_done_black_24dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="16dp"
            android:clickable="false"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:text="Mark Item as Gotten" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/fragment_grocery_bottom_sheet_delete"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:clickable="true"
        android:descendantFocusability="blocksDescendants"
        android:focusable="true"
        android:foreground="?android:attr/selectableItemBackground"
        android:orientation="horizontal"
        android:padding="16dp">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:clickable="false"
            android:focusable="false"
            android:focusableInTouchMode="false"
            app:srcCompat="@drawable/ic_delete_black_24dp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="16dp"
            android:clickable="false"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:text="Remove Item" />
    </LinearLayout>
</LinearLayout

The java class code for the Fragment is below. So for example if I click on the got menu (LinearLayout) the onClick method is not fired and the Log is not written also the SnackBar is not displayed

import android.os.Bundle;
import android.app.Fragment;
import android.support.design.widget.Snackbar;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;


public class GroceryItemsMenu extends Fragment {


    public GroceryItemsMenu() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        // Inflate the layout for this fragment
        final View view = inflater.inflate(R.layout.fragment_grocery_items_menu, container, false);

        LinearLayout delete = (LinearLayout) view.findViewById(R.id.fragment_grocery_bottom_sheet_delete);
        LinearLayout got = (LinearLayout) view.findViewById(R.id.fragment_grocery_bottom_sheet_got);
        LinearLayout search = (LinearLayout) view.findViewById(R.id.fragment_grocery_bottom_sheet_search);

        search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

        got.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Log.i("Item: ", "Got");
                Snackbar.make(getActivity().findViewById(R.id.groceryItemsCoordinatorLayout), "Got this Item", Snackbar.LENGTH_SHORT)
                        .setAction("Undo", new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {

                            }
                        }).show();
            }
        });

        delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // Delete code here;
            }
        });

        return view;
    }
}

What am I doing wrong?

1 Answers
Related