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

  • <tfoot id='RoiWu'></tfoot>
    <i id='RoiWu'><tr id='RoiWu'><dt id='RoiWu'><q id='RoiWu'><span id='RoiWu'><b id='RoiWu'><form id='RoiWu'><ins id='RoiWu'></ins><ul id='RoiWu'></ul><sub id='RoiWu'></sub></form><legend id='RoiWu'></legend><bdo id='RoiWu'><pre id='RoiWu'><center id='RoiWu'></center></pre></bdo></b><th id='RoiWu'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='RoiWu'><tfoot id='RoiWu'></tfoot><dl id='RoiWu'><fieldset id='RoiWu'></fieldset></dl></div>
    • <bdo id='RoiWu'></bdo><ul id='RoiWu'></ul>
    1. <small id='RoiWu'></small><noframes id='RoiWu'>

      <legend id='RoiWu'><style id='RoiWu'><dir id='RoiWu'><q id='RoiWu'></q></dir></style></legend>

      1. 如何使用 TextWatcher 更新相同的 EditText?

        How to update the same EditText using TextWatcher?(如何使用 TextWatcher 更新相同的 EditText?)
        <tfoot id='VAXFu'></tfoot>
            <bdo id='VAXFu'></bdo><ul id='VAXFu'></ul>

            <small id='VAXFu'></small><noframes id='VAXFu'>

              <tbody id='VAXFu'></tbody>
          • <legend id='VAXFu'><style id='VAXFu'><dir id='VAXFu'><q id='VAXFu'></q></dir></style></legend>

            <i id='VAXFu'><tr id='VAXFu'><dt id='VAXFu'><q id='VAXFu'><span id='VAXFu'><b id='VAXFu'><form id='VAXFu'><ins id='VAXFu'></ins><ul id='VAXFu'></ul><sub id='VAXFu'></sub></form><legend id='VAXFu'></legend><bdo id='VAXFu'><pre id='VAXFu'><center id='VAXFu'></center></pre></bdo></b><th id='VAXFu'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='VAXFu'><tfoot id='VAXFu'></tfoot><dl id='VAXFu'><fieldset id='VAXFu'></fieldset></dl></div>

                • 本文介紹了如何使用 TextWatcher 更新相同的 EditText?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  在我的 Android 應用程序中,我需要實現一個 TextWatcher 接口來實現 onTextChanged.我遇到的問題是,我想用一些額外的字符串更新相同的 EditText.當我嘗試這樣做時,程序會終止.

                  In my Android application I need to implement a TextWatcher interface to implement onTextChanged. The problem I have is, I want to update the same EditText With some extra string. When I try to do this the program terminates.

                   final EditText ET = (EditText) findViewById(R.id.editText1);
                   ET.addTextChangedListener(new TextWatcher() {
                  
                          @Override
                          public void onTextChanged(CharSequence s, int start, int before, int count)
                          {
                              try
                              {
                                   ET.setText("***"+ s.toString());
                                   ET.setSelection(s.length());
                              }
                              catch(Exception e)
                              {
                                  Log.v("State", e.getMessage());
                              }
                          }
                  
                          @Override
                          public void beforeTextChanged(CharSequence s, int start, int count, int after)
                          {
                  
                          }
                  
                          @Override
                          public void afterTextChanged(Editable s)
                          {               
                          }
                      });
                  

                  我的程序終止了,即使我嘗試在我的代碼中捕獲異常,它仍然終止.有誰知道為什么會發生這種情況以及我如何做到這一點?謝謝.

                  My program terminates and even I try to catch the exception like in my code still it terminates. Does anyone have any idea why this happens and how I can achieve this? Thanks.

                  推薦答案

                  TextView 的內容在 onTextChanged 事件上不可編輯.

                  The content of the TextView is uneditable on the onTextChanged event.

                  相反,您需要處理 afterTextChanged 事件才能對文本進行更改.

                  Instead, you need to handle the afterTextChanged event to be able to make changes to the text.

                  更詳盡的解釋參見:Android TextWatcher.afterTextChanged vs TextWatcher.onTextChanged

                  注意:錯誤onTextChanged

                  顯然,您正在通過不斷更改 afterTextChanged 事件上的 text 導致無限循環.

                  Obvioulsy, you are causing an endless loop by continuously changing the text on afterTextChanged event.

                  來自 參考:

                  public abstract void afterTextChanged (Editable s)
                  調用此方法是為了通知您,在 s 中的某處,文本已被改變了.從此對 s 進行進一步更改是合法的回調,但注意不要讓自己陷入無限循環,因為您所做的任何更改都會導致再次調用此方法遞歸地....

                  • 建議1:如果可以的話,檢查s是否已經在事件觸發時是你想要的.

                    • Suggestion 1: if you can, check if the s is already what you want when the event is triggered.

                      @Override
                      public void afterTextChanged(Editable s)
                      {    
                          if( !s.equalsIngoreCase("smth defined previously"))
                               s = "smth defined previously";              
                      }
                      

                    • 建議 2:如果您需要做更復雜的事情(格式化、驗證)您可以使用 synchronized 方法-textwatcher">這個發帖.
                    • Suggestion 2: if you need to do more complex stuff (formatting, validation) you can maybe use a synchronized method like in this post.
                    • 注意 2:將輸入格式化為部分隱藏,并用 n 個星號直到最后一個 4 個字符(****四個)

                      Note 2 : Formatting the input as partially hidden with n stars till the last 4 chars ( ****four)

                      您可以在建議 1 中使用類似的內容:

                      You can use something like this in suggestion 1:

                          @Override
                          public void afterTextChanged(Editable s)
                          {    
                             String sText = ET.getText().toString()
                      
                              if( !isFormatted(sText))
                                   s = format(sText);              
                          }
                          bool isFormatted(String s)
                          {
                           //check if s is already formatted
                          }
                      
                          string format(String s)
                          {
                            //format s & return
                          }
                      

                      這篇關于如何使用 TextWatcher 更新相同的 EditText?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  How can I detect integer overflow on 32 bits int?(如何檢測 32 位 int 上的整數溢出?)
                  Local variables before return statements, does it matter?(return 語句之前的局部變量,這有關系嗎?)
                  How to convert Integer to int?(如何將整數轉換為整數?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在給定范圍內創建一個隨機打亂數字的 int 數組)
                  Inconsistent behavior on java#39;s ==(java的行為不一致==)
                  Why is Java able to store 0xff000000 as an int?(為什么 Java 能夠將 0xff000000 存儲為 int?)

                  <small id='521e2'></small><noframes id='521e2'>

                  <tfoot id='521e2'></tfoot>

                    • <bdo id='521e2'></bdo><ul id='521e2'></ul>

                          <tbody id='521e2'></tbody>
                        <i id='521e2'><tr id='521e2'><dt id='521e2'><q id='521e2'><span id='521e2'><b id='521e2'><form id='521e2'><ins id='521e2'></ins><ul id='521e2'></ul><sub id='521e2'></sub></form><legend id='521e2'></legend><bdo id='521e2'><pre id='521e2'><center id='521e2'></center></pre></bdo></b><th id='521e2'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='521e2'><tfoot id='521e2'></tfoot><dl id='521e2'><fieldset id='521e2'></fieldset></dl></div>
                        <legend id='521e2'><style id='521e2'><dir id='521e2'><q id='521e2'></q></dir></style></legend>

                            主站蜘蛛池模板: 日韩三区在线观看 | 成人国产精品久久久 | 亚洲视频二区 | 亚洲国产精品久久人人爱 | 综合色站导航 | 日日艹夜夜艹 | 国产大学生情侣呻吟视频 | 成人免费看片又大又黄 | 日本一区二区三区在线观看 | 国产日韩精品在线 | 国产一区二区在线视频 | 精品少妇v888av | 欧美视频免费在线观看 | 午夜影院| 亚洲视频手机在线 | 国精产品一区二区三区 | 国产精品免费一区二区三区四区 | 91国内精精品久久久久久婷婷 | 一区二区三区四区在线 | 国产一区二区三区日韩 | 麻豆毛片 | 365夜爽爽欧美性午夜免费视频 | 五月婷六月丁香 | 亚洲精品乱码久久久久久9色 | 精品欧美黑人一区二区三区 | 欧美日韩视频在线第一区 | 亚洲精品久久久一区二区三区 | 野狼在线社区2017入口 | 日日操夜夜操天天操 | 亚洲一区二区在线视频 | 亚洲精品二区 | 久久精品国产亚洲 | 一区二区在线看 | 国产免费一区二区 | 欧美成人激情视频 | 可以免费观看的av | 国产美女在线观看 | 97在线观看| 鸳鸯谱在线观看高清 | 超碰97人人人人人蜜桃 | 久久久精品网 |