久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

按下后退時(shí) EditText 不會(huì)觸發(fā)更改

EditText does not trigger changes when back is pressed(按下后退時(shí) EditText 不會(huì)觸發(fā)更改)
本文介紹了按下后退時(shí) EditText 不會(huì)觸發(fā)更改的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

限時(shí)送ChatGPT賬號(hào)..

在帶有購(gòu)物車(chē)的應(yīng)用程序中,我提供了通過(guò) EditText 更改商品數(shù)量的選項(xiàng),該選項(xiàng)只允許輸入數(shù)字.
一切正常,除非用戶(hù)更改字段然后按返回鍵隱藏軟鍵盤(pán).在這種情況下,該字段顯示了更改的值,但我不知道如何檢測(cè)此更改并對(duì)其做出反應(yīng).等待切換到另一個(gè)活動(dòng)不是一種選擇.
當(dāng)用戶(hù)使用完成"按鈕確認(rèn)時(shí),我可以使用OnEditorActionListener"來(lái)處理它.但是后退鍵呢?

In an application with shopping cart, I give the option to change the amount of items via an EditText which allows only numerical input.
Everything works fine, except when the user changes the field and then presses the back key to hide the soft keyboard. In this case, the field shows the changed value, but I don't know how I can detect this change and react on it. Waiting for a switch to another activity is not an option.
When the user confirms with "done" button, I can handle this with a "OnEditorActionListener". But what about the back key?

更新:
事實(shí)證明,使用返回鍵關(guān)閉軟鍵盤(pán)時(shí),編輯字段上的 onKeyDown/onBackPressed 和 OnKeyListener 都不會(huì)觸發(fā).

update:
As it turned out, neither onKeyDown / onBackPressed nor OnKeyListener on the edit field do trigger when closing the soft keyboard with back key.

推薦答案

我在前段時(shí)間寫(xiě)的一個(gè)應(yīng)用程序中遇到了同樣的問(wèn)題.它現(xiàn)在已停產(chǎn),但這不是你的問(wèn)題 xD.

I had the same problem in an application which i wrote some time ago. It is discontiuned now but that's not your question xD.

事實(shí)上,沒(méi)有選項(xiàng)可以跟蹤這樣的操作,但我找到了一個(gè)很好的(或多或少)解決方案來(lái)添加這樣的功能.這在理論上很簡(jiǎn)單,但我認(rèn)為它也是一個(gè)黑客".

In fact there is no option to track such a operation, but i've found a great (more or less) solution to add such a functionality. It's quite simple in theory but it's a "hack" too i think.

因此,您需要一個(gè)包含您的應(yīng)用程序或特殊區(qū)域的自定義線(xiàn)性布局.之后,您必須為其添加一個(gè)偵聽(tīng)器.這僅適用于縱向模式.

So what you will need is a custom linear layout which contains your application, or a special region. After that you have to add it a listener. And this will work only in portrait mode.

所以這里是代碼:(對(duì)不起,我不記得出處了)

So here to the code: (i'm sorry but i can't remember the source)

自定義布局:

LinearLayoutThatDetactsSoftwarekeyboard.java(這是布局 xD 的原始名稱(chēng))

LinearLayoutThatDetactsSoftwarekeyboard.java (that's the original name of the layout xD)

package com.tundem.people.Layout;

import android.app.Activity;
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.LinearLayout;

/*
 * LinearLayoutThatDetectsSoftKeyboard - a variant of LinearLayout that can detect when 
 * the soft keyboard is shown and hidden (something Android can't tell you, weirdly). 
 */

public class LinearLayoutThatDetectSoftkeyboard extends LinearLayout {

    public LinearLayoutThatDetectSoftkeyboard(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public interface Listener {
        public void onSoftKeyboardShown(boolean isShowing);
    }

    private Listener listener;

    public void setListener(Listener listener) {
        this.listener = listener;
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int height = MeasureSpec.getSize(heightMeasureSpec);
        Activity activity = (Activity) getContext();
        Rect rect = new Rect();
        activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
        int statusBarHeight = rect.top;
        int screenHeight = activity.getWindowManager().getDefaultDisplay().getHeight();
        int diff = (screenHeight - statusBarHeight) - height;
        if (listener != null) {
            listener.onSoftKeyboardShown(diff > 128); // assume all soft
                                                        // keyboards are at
                                                        // least 128 pixels high
        }
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

}

以及如何添加監(jiān)聽(tīng)器:

final LinearLayoutThatDetectSoftkeyboard lltodetectsoftkeyboard = (LinearLayoutThatDetectSoftkeyboard) findViewById(R.id.LinearLayout_SoftKeyboard);
    lltodetectsoftkeyboard.setListener(new Listener() {

        public void onSoftKeyboardShown(boolean isShowing) {
            if (actMode == MODE_SMS && isShowing) {
                findViewById(R.id.LinearLayout_bottomnavigationbar).setVisibility(View.GONE);
            } else {
                findViewById(R.id.LinearLayout_bottomnavigationbar).setVisibility(View.VISIBLE);
            }
        }
    });

LinearLayout 添加了一個(gè)監(jiān)聽(tīng)器,每當(dāng) layoutheight 改變至少 128 像素時(shí)都會(huì)調(diào)用該監(jiān)聽(tīng)器.這是一個(gè)技巧,它不適用于小于 128 像素的鍵盤(pán)(但我認(rèn)為每個(gè)鍵盤(pán)都有這樣的高度)如果 LayoutHeight 已更改,您將收到通知它是否現(xiàn)在顯示.

The LinearLayout adds a Listener which will be called each time the layoutheight changes by at least 128 pixels. It's a trick and it won't work with keyboards that are smaller than 128 pixels (but i think each keyboard has such a height) If the LayoutHeight has Changed you will get notified if it's showing now or not.

希望我的回答有用.也許您再次在 StackOverFlow 上找到了真正的來(lái)源.所以我不會(huì)偷別人的天才.學(xué)分歸未知人所有;)

I hope my answer was useful. Perhaps you find the real source here on StackOverFlow again. I won't steal someones genius so. Credits goes to the unknown person ;)

這篇關(guān)于按下后退時(shí) EditText 不會(huì)觸發(fā)更改的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Cut, copy, paste in android(在android中剪切、復(fù)制、粘貼)
android EditText blends into background(android EditText 融入背景)
Change Line Color of EditText - Android(更改 EditText 的線(xiàn)條顏色 - Android)
EditText showing numbers with 2 decimals at all times(EditText 始終顯示帶 2 位小數(shù)的數(shù)字)
Changing where cursor starts in an expanded EditText(更改光標(biāo)在展開(kāi)的 EditText 中的開(kāi)始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問(wèn)題)
主站蜘蛛池模板: 一区二区三区小视频 | 别c我啊嗯国产av一毛片 | 国产污视频在线 | 欧美精品一区二区三区四区 在线 | 人人鲁人人莫人人爱精品 | 欧美日韩亚洲一区 | 欧美三区视频 | 91久久久久久久久久久久久 | 久久噜噜噜精品国产亚洲综合 | 蜜桃av一区二区三区 | 国产精品久久久久久中文字 | 亚洲精品一区二区在线观看 | 国产精品久久久久久亚洲调教 | 国产精品久久久精品 | 一区二区三区在线播放 | 丁香五月网久久综合 | 久久欧美高清二区三区 | 久草99 | 日韩av看片 | 天天综合久久网 | 欧美精品一区在线 | 欧美日韩不卡合集视频 | 五月天国产 | 福利精品在线观看 | 亚洲视频在线播放 | 久久国产激情视频 | 国产精品久久久久国产a级 欧美日韩国产免费 | 久久中文字幕电影 | 超碰在线免费av | 男人的天堂久久 | 天天干夜夜操 | 久久av一区二区三区 | 中文欧美日韩 | 欧美极品在线 | 亚洲电影第三页 | 久久久精彩视频 | 国产亚洲一区精品 | 亚洲一区二区在线播放 | 亚洲一区二区三区四区五区中文 | 国产激情一区二区三区 | 91视频导航 |