[英]Custom Functionality: Add Specific Symbol While Typing Into Edittext
我正在嘗試向現有應用程序添加功能,該功能是在用戶鍵入內容時使用空格添加特定符號。 我已經用afterTextChaanged();
嘗試過afterTextChaanged();
我想要做的是支持用戶類型:很好,謝謝,然后應該將其自動轉換為:@i @am @fine @thankyou。 你能幫我嗎? 提前謝謝了。
edittext.addTextChangedListener(new TextWatcher(){
public void afterTextChanged(Editable s) {
edittext.removeTextChangedListener(this);
String oldstr=edittext.getText().toString();
String newstr=oldstr.replaceAll("\\s+","@");
edittext.setText(newstr);
edittext.removeTextChangedListener(this);
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count){
}
});
在這里看看。
您應該可以使用' @'
類' @'
替換所有空格。
剛打電話
string = string.replace(" ", " @");
在您的聽眾中。
當然,您還應該注意第一個單詞,該單詞(通常)之前不能有任何空格。 您可以使用占位符,例如
<string name="converted_string">@%1$s</string>
然后在java中
your_textView.setText(getString(R.string.converted_string, yourNewReplaceString));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.