2017-08-08 4 views
3

BottomSheetDialogメニューののonClickメソッドを呼び出す問題があります。BottomSheetDialog setOnClickListenerが起動しません

これは、FragmentのJavaクラスコードは、下記のXMLフラグメントレイアウト又は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 

あります。 I GOTメニュー(のLinearLayout)をクリックしてくださいonClick方法が発射されていないとログにも書き込まれていないのであれば、たとえばSnackBarは私が間違って何をやっている

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; 
    } 
} 

が表示されていませんか?

+0

トライ削除ラインアプリを実装して拡張しますlayout_behavior =「android.support.design.widget.BottomSheetBehavior」 –

+0

これは、コードアクティビティを投稿することができます – wodubayo

+0

を動作しないようですか? –

答えて

0

使用:publicクラスGroceryItemsMenuは、フラグメントがView.OnClickListener

+0

私は、実装にView.OnClickListenerを追加し、public void onClick(View v)を実装しました。私はR.id.LayoutNameを切り替えたが、それは仕事をしなかった – wodubayo

関連する問題