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

android on Text Change Listener

android on Text Change Listener(android on Text Change Listener)
本文介紹了android on Text Change Listener的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我有一個情況,有兩個字段.field1field2.我所想要的當(dāng) field1 改變時, to do 為空 field2,反之亦然.所以只在最后一個字段上有內(nèi)容.

I have a situation, where there are two fields. field1 and field2. All I want to do is empty field2 when field1 is changed and vice versa. So at the end only one field has content on it.

field1 = (EditText)findViewById(R.id.field1);
field2 = (EditText)findViewById(R.id.field2);

field1.addTextChangedListener(new TextWatcher() {

   public void afterTextChanged(Editable s) {}

   public void beforeTextChanged(CharSequence s, int start,
     int count, int after) {
   }

   public void onTextChanged(CharSequence s, int start,
     int before, int count) {
      field2.setText("");
   }
  });

field2.addTextChangedListener(new TextWatcher() {

   public void afterTextChanged(Editable s) {}

   public void beforeTextChanged(CharSequence s, int start,
     int count, int after) {
   }

   public void onTextChanged(CharSequence s, int start,
     int before, int count) {
     field1.setText("");
   }
  });

如果我僅將 addTextChangedListener 附加到 field1 則效果很好,但是當(dāng)我對應(yīng)用程序崩潰的兩個領(lǐng)域都這樣做.顯然是因為他們試圖改變彼此無限期.一旦 field1 更改,此時它會清除 field2field2 已更改,因此它將清除 field1 等等...

It works fine if I attach addTextChangedListener to field1 only, but when I do it for both fields the app crashes. Obviously because they try to change each other indefinitely. Once field1 changes it clears field2 at this moment field2 is changed so it will clear field1 and so on...

有人可以提出任何解決方案嗎?

Can someone suggest any solution?

推薦答案

您可以添加一個檢查以僅在字段中的文本不為空時(即長度不為0時)清除.

You can add a check to only clear when the text in the field is not empty (i.e when the length is different than 0).

field1.addTextChangedListener(new TextWatcher() {

   @Override
   public void afterTextChanged(Editable s) {}

   @Override    
   public void beforeTextChanged(CharSequence s, int start,
     int count, int after) {
   }

   @Override    
   public void onTextChanged(CharSequence s, int start,
     int before, int count) {
      if(s.length() != 0)
        field2.setText("");
   }
  });

field2.addTextChangedListener(new TextWatcher() {

   @Override
   public void afterTextChanged(Editable s) {}

   @Override
   public void beforeTextChanged(CharSequence s, int start,
     int count, int after) {
   }

   @Override
   public void onTextChanged(CharSequence s, int start,
     int before, int count) {
      if(s.length() != 0)
         field1.setText("");
   }
  });

TextWatcher 的文檔此處.

還請遵守命名約定.

這篇關(guān)于android on Text Change Listener的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環(huán)繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數(shù)據(jù)庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 亚洲欧洲成人av每日更新 | 国产亚洲精品区 | 国产黄色av网站 | 韩国av网站在线观看 | 国产一区二区三区免费视频 | 黄色在线免费观看 | 亚洲精品一区二区二区 | 日日夜夜天天 | 男人亚洲天堂 | 国产h视频 | 99久久久久久| 精品av | 人人干人人玩 | 欧美一区二区三区在线视频 | 久久这里有精品 | 日日夜夜精品视频 | 999国产精品视频 | 国产精品久久久久无码av | 欧美精品一区二区免费 | 欧美成人一区二区 | 懂色av色香蕉一区二区蜜桃 | 粉嫩高清一区二区三区 | 欧美精品一二三 | 亚洲www啪成人一区二区麻豆 | 韩国av网站在线观看 | 久久一区二区视频 | 一级毛片免费完整视频 | 美美女高清毛片视频免费观看 | 成年人在线视频 | 欧美一级毛片免费观看 | 人人cao| 精品免费国产视频 | 久久久久成人精品 | 蜜臀av日日欢夜夜爽一区 | 欧美久久久久 | 国产精品99久久久久久久vr | 久久精品免费看 | 欧美国产亚洲一区二区 | 91免费电影 | 亚洲天堂色 | 91精品导航|