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

Android:用戶完成編輯后評估 EditText

Android: Evaluate EditText after the user finishes editing(Android:用戶完成編輯后評估 EditText)
本文介紹了Android:用戶完成編輯后評估 EditText的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我想要什么我有一個 EditText,用戶可以在其中輸入一個值,例如 10.40.用戶完成編輯后,我將他的輸入格式化為貨幣,例如,上述值將格式化為 10.40 美元(在 Locale.US 的情況下).然后我在用戶之前編輯的相同 EditText 中顯示該結果.

What I want I have an EditText, where the user can enter a value, such as 10.40. Once the user is done editing I am formatting his input to a currency, for instance the above mentioned value would get formatted to $10.40 (in the case of Locale.US). And I display that result in the same EditText that the user previously edited.

問題因為我要格式化(即修改)他的輸入,所以我需要知道他什么時候完成(所以我的格式化不會干擾他正在進行的輸入).

Problem Because I am going to format (i.e. modify) his input, I need to know when he's done (so my formatting does not interfer with his ongoing input).

我嘗試了什么TextWatcher 不是一個選項,因為它會在每次編輯時觸發,因此當用戶輸入一、零、四、點和零(=10.40)時.我目前正在使用 OnFocusChangeListener ,它可以按需要工作,但問題是:我的應用程序中有按鈕,如果用戶在編輯 EditText 后單擊按鈕,則 EditText 不會失去焦點,因此我的格式化代碼永遠不會被調用...

What I tried TextWatcher is not an option, since it fires on every single edit, hence when the user enters one, zero, four, dot and zero (=10.40). I am currently using an OnFocusChangeListener which works as desired, BUT the problem is: I have buttons in my application and if the user clicks on a button after editing the EditText the EditText won't lose Focus, hence my formatting code never get's called ...

在此之后,我嘗試弄亂按鈕的焦點,將其設置為 FocusableInTouchMode - 這導致按鈕必須單擊兩次才能觸發(這是不行的),因為它第一次獲得焦點并獲得第二次激活.經過這么多的黑客攻擊,我想知道是否有人知道如何解決這個困境.

After this I tried messing around with the button's focus, setting it to FocusableInTouchMode - which results in the button having to be clicked twice in order to fire (which is a no go), since it gains focus the first time and get's activated the second time. After so much hacking around I was wondering if anyone got an idea as how to solve this dilemma.

一些代碼

我將以下 OnFocusChangeListener 添加到我上面描述的功能的 EditText 中.EditText 封裝在 CurrencyTextbox 中(實際上并不相關):

I add the following OnFocusChangeListener to my EditText whose function I described above. The EditText is encapsulated within a CurrencyTextbox (which is not really relevant):

@Override
protected OnFocusChangeListener getOnFocusChangeListener() {
    return new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                //Member variable in the class which contains an EditText
                CurrencyTextbox.this.hadFocus = true;
            } else {
                // Thes EditText has lost focus
                Log.v(TAG, "Lost focus.");
                if (CurrencyTextbox.this.hadFocus) {
                    // We previously had focus, now we lost it, format the user input!
                    // Get current value of the Textbox
                    String value = CurrencyTextbox.this.textbox.getText().toString();
                    // Formatting the user input
                    value = String.format(//Doing some formatting);
                    // Reset the had focus
                    CurrencyTextbox.this.hadFocus = false;
                }
            }
        }
    };
}

但是問題是,上面的 OnFocusChangelistener 只有在我的 EditText 失去焦點時才會被調用,但是當我點擊 Activity 中的按鈕時它不會失去焦點,并且如上所述,設置 Button 的 isFocusableInTouchMode 是不可行的為真,因為它需要每次點擊兩次才能觸發.

The problem however is, the above OnFocusChangelistener only get's called if my EditText loses focus, but it does NOT lose focus when I click on a button in my Activity, and as stated above, it is not feasible to set the Button's isFocusableInTouchMode to true, as it then needs to be clicked twice every time to fire.

推薦答案

我做了一些研究,發現這個線程.它詳細說明了您遇到的類似問題(按鈕沒有獲得焦點).請嘗試以下操作:在您的按鈕上,設置 setFocusable(true)(不是 setFocusableInTouchMode!因為這會產生您在 OP 中聲明的煩人行為),然后在您的按鈕上設置以下 OnClickListener:

I did some research and amongst other things I found this thread. It elaborates upon a similar issue that you're having (of the button not gaining focus). Try the following: On your buttons, set setFocusable(true) (NOT setFocusableInTouchMode! As this spawns the annoying behaviour you stated in your OP), then set the following OnClickListener on your Buttons:

    return new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO workaround because of android issue nr. 2705
            button.requestFocusFromTouch();
            // Do some stuff to handle OnClick
        }
    };

但他們可能應該只修復按鈕的焦點問題,當前的行為確實會導致一些問題(比如你的).

But they should probably just fix the focus stuff for buttons, the current behaviour really does cause some issues (like yours).

這篇關于Android:用戶完成編輯后評估 EditText的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

Cut, copy, paste in android(在android中剪切、復制、粘貼)
android EditText blends into background(android EditText 融入背景)
Change Line Color of EditText - Android(更改 EditText 的線條顏色 - Android)
EditText showing numbers with 2 decimals at all times(EditText 始終顯示帶 2 位小數的數字)
Changing where cursor starts in an expanded EditText(更改光標在展開的 EditText 中的開始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問題)
主站蜘蛛池模板: 久久99久久99久久 | 欧美久久精品一级c片 | 日韩高清中文字幕 | 日韩精品一区二 | 久久精品一级 | 日韩在线不卡 | 污书屋 | 99福利视频| 97伊人 | 日本成人久久 | 三级黄视频在线观看 | 亚洲欧洲精品成人久久奇米网 | 亚洲狠狠 | 国产一级网站 | 亚洲精品亚洲人成人网 | 天天爽夜夜操 | 午夜亚洲 | 久草网站 | 日韩福利在线观看 | 国产精品乱码一区二区三区 | 中文字字幕一区二区三区四区五区 | www.9191.com| 伊人色综合久久天天五月婷 | 91精品国产91久久久久久三级 | 中文精品视频 | 国产精品久久久久久久久久三级 | 亚洲福利片 | www.久久| 亚洲人成在线播放 | 国产片一区二区三区 | 一本色道精品久久一区二区三区 | 精品亚洲一区二区三区 | 美女黄视频网站 | 二区av| 欧美v日韩v| 精品国产乱码久久久久久丨区2区 | aaaaaa大片免费看最大的 | 激情福利视频 | 国产95在线 | 国产色| 欧美在线a |