Android 按钮。设置按下(true)和BaseAdapter
我试图创建一个包含按钮的列表,并通过编程控制这些按钮的按下状态 我为这些按钮创建了一个选择器:Android 按钮。设置按下(true)和BaseAdapter,android,button,baseadapter,Android,Button,Baseadapter,我试图创建一个包含按钮的列表,并通过编程控制这些按钮的按下状态 我为这些按钮创建了一个选择器: <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/drw_blue_logincombination_pin_pressed" a
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/drw_blue_logincombination_pin_pressed" android:state_pressed="true"/>
<item android:drawable="@drawable/drw_blue_logincombination_pin_normal" android:state_pressed="false"/>
</selector>
当我输入activity并comb.pin==true时,按钮被设置为按下,但仅持续一秒钟,然后被设置为未按下(未通过onTouch侦听器)
但是如果我创建第二行,第一行将被更新,然后它将显示正确的状态(按下)
也许我犯了一些基本的错误,但我不明白为什么它不起作用,有人能帮我吗
提前谢谢
编辑:
以下是按钮在适配器行布局中的声明方式:
<ImageButton
android:id="@+id/btnPin"
android:layout_width="120dp"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:background="@drawable/button_pin"
android:textAppearance="?android:attr/textAppearanceLarge" />
这可能是由于按钮的初始默认状态,我猜是-未按下-对吗?BaseAdapter实际上会对其进行微调(按下holder.pin.setPressed(comb.pin);),但由于该按钮不是切换按钮,因此会立即释放该按钮。我想这就是问题所在。试着删除android:state\u pressed=“false”谢谢g00dy&blackbelt,我已经编辑了关于按钮在布局中如何声明的问题,没有state\u pressed,我将用state\u pressed=“true”测试它,它也不起作用:(我也有这个问题-你解决了吗?
<ImageButton
android:id="@+id/btnPin"
android:layout_width="120dp"
android:layout_height="match_parent"
android:layout_margin="5dp"
android:background="@drawable/button_pin"
android:textAppearance="?android:attr/textAppearanceLarge" />