简体   繁体   中英

OnTouchListener webview always looping

i want to detect if i touch edit text type on my webview, i will show the floating action buttons. and if i touch unknown type the floating action buttons will be hide.

but here when i touch some position on my webview, it's looping between 4 / 5 times until i get the real touch type.

here is my code :

   @Override
    public boolean onTouch(View v, MotionEvent event) {
        WebView.HitTestResult hitTestResult = ((WebView) v).getHitTestResult();

        if (hitTestResult.getType() == WebView.HitTestResult.EDIT_TEXT_TYPE) {
            this.showKeyboard();
            this.floatingActionButton.setVisibility(View.VISIBLE);
            this.fabKeyboard.setVisibility(View.VISIBLE);
        }else{
            this.hideKeyboard();
            this.floatingActionButton.setVisibility(View.GONE);
            this.fabKeyboard.setVisibility(View.GONE);
        }


        Log.d("HIT RESULT", hitTestResult.getExtra() + " " + hitTestResult.getType());
        return false;
    }

here is my log :

I/InputMethodManager: toggleSoftInput(I,I)
D/HIT RESULT: null 9
I/InputMethodManager: toggleSoftInput(I,I)
D/HIT RESULT: null 9
I/InputMethodManager: toggleSoftInput(I,I)
D/HIT RESULT: null 9
D/ViewRootImpl@c99fda4[MainActivity]: ViewPostIme pointer 1
I/InputMethodManager: toggleSoftInput(I,I)
D/HIT RESULT: null 9 
// 9 IS Edit Text Type

D/HIT RESULT: null 9
D/InputMethodManager: HSIFW - flag : 0
D/HIT RESULT: null 0
D/InputMethodManager: HSIFW - flag : 0
D/HIT RESULT: null 0
D/InputMethodManager: HSIFW - flag : 0
D/HIT RESULT: null 0
D/InputMethodManager: HSIFW - flag : 0
D/HIT RESULT: null 0
// 0 Is Unknown Type

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM