0

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,

4

1 回答 1

0

临时解决方案:

...
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()
});
于 2012-10-17T08:10:18.033 回答