Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
502 views
in Technique[技术] by (71.8m points)

onhover - onHoverListener doesn't work in Android

In android document, it mentions supporting the "hover" event since 4.0 (ie. API level 14 and up). But somehow, it doesn't work. Even I tried out the sample code in ApiDemo, which is from Android Sample, it didn't work. My current device is Android 4.0.4. Should I upgrade it to 4.2.2?

Sample code is something as below. Did you have a solution to it? Thanks a lot.

Code:


View container = findViewById(R.id.container);
    container.setOnHoverListener(new View.OnHoverListener() {
        @Override
        public boolean onHover(View v, MotionEvent event) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_HOVER_ENTER:
                    mMessageTextView.setText(Hover.this.getResources().getString(
                            R.string.hover_message_entered_at,
                            event.getX(), event.getY()));
                    break;
                case MotionEvent.ACTION_HOVER_MOVE:
                    mMessageTextView.setText(Hover.this.getResources().getString(
                            R.string.hover_message_moved_at,
                            event.getX(), event.getY()));
                    break;
                case MotionEvent.ACTION_HOVER_EXIT:
                    mMessageTextView.setText(Hover.this.getResources().getString(
                            R.string.hover_message_exited_at,
                            event.getX(), event.getY()));
                    break;
            }
            return false;
        }
    });

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Hovering requires support from the hardware. The only thing likely to support it is a stylus. It won't work with just your finger.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...