gpt4 book ai didi

android - BottomSheetDialog setOnClickListener 未触发

转载 作者:太空狗 更新时间:2023-10-29 14:42:31 25 4
gpt4 key购买 nike

我在触发 BottomSheetDialog 菜单的 setOnClickListeneronClick 方法时遇到问题。

这是 xml fragment 布局或 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

Fragment 的 java 类代码如下。因此,例如,如果我单击获取的菜单 (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;
}
}

我做错了什么?

最佳答案

使用:公共(public)类 GroceryItemsMenu 扩展 Fragment 实现 View.OnClickListener

关于android - BottomSheetDialog setOnClickListener 未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45558785/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com