首页 > 解决方案 > 如何在 BootstrapDropDown 的项目中添加 onclick 事件

问题描述

我需要知道您何时单击其中一个元素

可以使用 'android:onClick' 从 xml 完成吗?这是我的代码:

<com.beardedhen.androidbootstrap.BootstrapDropDown
                app:bootstrapExpandDirection="up"
                android:text="Cards"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#ea2c2c"
                app:bootstrapBrand="primary"
                app:bootstrapSize="lg"
                app:dropdownResource="@array/dropdown_cards"
                app:showOutline="false"/>

@array/dropdown_cards :
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<string-array name="dropdown_cards">
     <item android:onClick="btnCardOption">@string/analyze</item>
    <item>@string/history</item>
</string-array>

标签: javaandroid-layoutandroid-bootstrap

解决方案


也许您可以通过创建下拉实例然后添加 onClickListener 从您的活动/片段代码中添加它。


推荐阅读