The documentation on android docs is incorrect. Here it states that pickDropPoint.getDrawableState()[android.R.attr.state_pressed]
returns true
or false
, but instead it returns 1
or 0
, an **int**
.
I had to do the following to get it working
<ImageButton
android:id="@+id/pickDropPoint"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="6"
android:background="#EEeeeee4"
android:contentDescription="pick or drop point"
android:src="@drawable/pickupdrop" />
The drawable xml for pressed feel
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:src="@drawable/start32" android:state_pressed="true"/>
<item android:src="@drawable/end32" android:state_pressed="false"/>
<corners
android:bottomLeftRadius="3dp"
android:bottomRightRadius="3dp"
android:topLeftRadius="3dp"
android:topRightRadius="3dp" />
</selector>
In code, you dont need the for loop as suggested by @slup
whichPoint = (pickDropPoint.getDrawableState()[android.R.attr.state_pressed] > 1 ? PICKUP : DROP);