The selector responds slowly - sometimes without firing at all, before starting the next operation

I defined this selector:

<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 is 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 to exit the current activity. this.finish() However, when testing the button does not always switch to "backarrow_blueshiny", namely when pressed very quickly.

So the problem is that the selector fires more slowly than the onTouch event (MotionEvent.ACTION_UP).

Is there anything I can do to make sure the selector is not "laggy"?

+3
source share
3 answers

laggier, Android? , , - , , , . , , , android:background , ImageButton android:src, .

.

<Button
    android:layout_width="90dip"
    android:layout_height="wrap_content"
    android:background="@drawable/selector_back_button"
    android:layout_alignParentLeft="true"
    android:layout_alignParentBottom="true" 
    />
0

OnTouchListener:

@Override
public boolean onTouch(View v, MotionEvent event) {
    switch (event.getActionMasked()) {
        case MotionEvent.ACTION_DOWN:
            button.setPressed(true);
            break;
        case MotionEvent.ACTION_UP:
            // optional, should work without next line
            // button.setPressed(false); 
            break;
    }

    return false;
}
+5

. . "onTouch". onClickListener onTouchListener, , .

, , onClick

   if (actionPerformed == MotionEvent.ACTION_UP)
+2

All Articles