【Android】【BUG】BRVAH3.x实现多级菜单中子菜单无法点击的问题

问题

使用BRVAH进行多级菜单效果实现时,子菜单的点击事件怎么也不行,根本无法获取点击事件。

问题代码

        treeAdapter.addChildClickViewIds(R.id.tv_child_item);
        treeAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
    
    
            @SuppressLint("NonConstantResourceId")
            @Override
            public void onItemChildClick(@NonNull BaseQuickAdapter adapter, @NonNull View view, int position) {
    
    
                Log.e("TAG", "9999999999999999999");
                if (view.getId() == R.id.tv_child_item) {
    
    
                    Log.e("TAG", "点击的是:" + adapter.getData().get(position).toString());
                }
            }
        });

问题原因

子项的xml布局

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/tv_child_item"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clickable="true"
        android:focusable="true"
        android:gravity="start|center_vertical"
        android:padding="5dp"
        android:paddingStart="20dp"
        android:textColor="#484848"
        android:textSize="@dimen/sp_14"
        android:textStyle="normal" />

修改为

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="@dimen/dp_40"
    android:background="#FFFFFF">

    <TextView
        android:id="@+id/tv_child_item"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clickable="true"
        android:focusable="true"
        android:gravity="start|center_vertical"
        android:padding="5dp"
        android:paddingStart="20dp"
        android:textColor="#484848"
        android:textSize="@dimen/sp_14"
        android:textStyle="normal" />
</LinearLayout>

这就解决了,这谁顶得住啊…

猜你喜欢

转载自blog.csdn.net/qq_43358469/article/details/131665012
今日推荐