簡體   English   中英

在Android中輸入自動完成文本時刪除空格

[英]Remove whitespace when input autocomplete text in Android

在注冊活動中,重點關注電子郵件EditTextField(而不是autocompletext只是edittext),我可以放置經常使用的電子郵件。

但它總是輸入帶有空格的電子郵件。

就像,如果經常使用的電子郵件是'tester@test.com'

但是當我在鍵盤上選擇電子郵件時,輸入的空格為'tester@test.com'

選擇具有自動完成功能的電子郵件時,我想刪除空白

如果您知道這一點,請幫助我


我把它放在public void afterTextChanged(Editable s)

Log.d(TAG,"print input email " + "|" + editTextEmail.getText().toString() + "|");

D/JoinActivity: print input email |tester@tester|
D/JoinActivity: print input email |tester@tester|
D/JoinActivity: print input email |tester@tester |

當我在換文字后放進去時,

這樣打印重復,

2019-03-13 17:55:31.208 24374-24565/? D/InputTransport: Input channel constructed: fd=418
2019-03-13 17:55:31.208 24374-24565/? D/InputTransport: Input channel destroyed: fd=418
2019-03-13 17:55:31.208 14842-14842/com.example.thewell_dev.myapplication D/InputTransport: Input channel constructed: fd=79
2019-03-13 17:55:31.209 14842-14842/com.example.thewell_dev.myapplication D/InputTransport: Input channel destroyed: fd=82
2019-03-13 17:55:31.217 14842-14842/com.example.thewell_dev.myapplication V/InputMethodManager: Starting input: tba=android.view.inputmethod.EditorInfo@8a6ddd0 nm : com.example.thewell_dev.myapplication ic=com.android.internal.widget.EditableInputConnection@58201c9

嘗試這個

在您的editText.addTextChangedListener {....}中

加上這個

 @Override
 public void afterTextChanged(Editable s) {
 String result = s.toString().replaceAll(" ", "");
 editText.setText(result);
 }

要么

@Override
 public void afterTextChanged(Editable s) {
 String result= s.trim();
 editText.setText(result);

 }

您可以將TextWatcher添加到EditText中,以監視文本的更改並刪除前導/尾隨空白。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM