I have this Selector defined:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- PRESSED -->
<item android:state_pressed="true"
android:drawable="@drawable/backarrow_blueshiny" />
<!-- FOCUSED -->
<item android:state_focused="true"
android:drawable="@drawable/backarrow_blackshiny" />
<!-- DEFAULT -->
<item android:drawable="@drawable/backarrow_blackshiny" />
</selector>
and it’s used with this button:
<RelativeLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/bottomborder_glossy">
<!-- BACK -->
<ImageButton
android:id="@+id/filter_button_back"
android:layout_width="90dip"
android:layout_height="wrap_content"
android:src="@drawable/selector_back_button"
android:background="#00000000"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
and the onTouch event consists of:
public boolean onTouch(View v, MotionEvent event)
{
final int actionPerformed = event.getAction();
final int widgetID = v.getId();
if (actionPerformed == MotionEvent.ACTION_UP)
{
switch (widgetID)
{
case R.id.filter_button_back:
{
this.finish();
break;
}
}
}
return false;
}
what this button does is exit the current activity this.finish()
However, in my testing the button doesn’t always switch to “backarrow_blueshiny” – namely when pressing very fast.
So the problem is that the selector fires slower than the onTouch(MotionEvent.ACTION_UP) event.
Is there anything I can do to make sure that the selector isn’t “laggy” ?
Do you mean laggier than the typical Android selector behavior? In my experience, there’s always been a slight delay between a button press, and it being selected — I assume it’s to avoid showing a touch event when you’re just wanting to scroll, but it’s always annoyed me. If it’s more than the typical behavior, try using just a button, with the
android:backgroundset to the selector, rather than an ImageButton with theandroid:srcset to the selector.e.g.