Вопрос

I have some ImageView's:

The selector for right arrow button is:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="3" android:state_pressed="true"/> <!-- pressed -->
    <item android:drawable="1" android:state_enabled="false"/> <!-- enabled -->
    <item android:drawable="2"/> <!-- default -->

</selector>

(1, 2, 3 look like the ones in the picture below — 1 is for left arrow button, but the right's one looks like the same with opposite direction).

Now my problem is:

  1. When the user does click, I use setEnable() to change its status. It works.
  2. When the user does long click, again, I use setEnable() to change its status. But after the user released his finger, the button retains status as image #3.
  3. I tried: cancelLongPress(), clearFocus(), invalidate(), post(Runnable), postInvalidate(), refreshDrawableState()… but they didn't work.

The app uses minimum SDK 4 (Android 1.6). Could you help me?

Thanks,

Это было полезно?

Решение

Temporary solution:

...
imageView.setOnTouchListener(new View.OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_UP) {
            v.postDelayed(new Runnable() {

                @Override
                public void run() {
                    v.setEnabled(...);
                }// run()
            }, 200); // 200 ms is enough
        }

        return false;
    }// onTouch()
});
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top