android edittext 特殊字符,在android中使用edittext时删除特殊字符;

我需要删除字符,如果我添加任何特殊符号的编辑文本,而我正在输入数据,例如我输入一个单词smwinææ是一个特殊字符,所以如果我添加chareter编辑文本应该删除æ和通过替换æ.i使用的文本更改侦听器来仅显示smwin。检查以下在android中使用edittext时删除特殊字符;

email.addTextChangedListener(new TextWatcher() {

public void afterTextChanged(Editable s) {

// Abstract Method of TextWatcher Interface.

System.out.println("started after");

}

public void beforeTextChanged(CharSequence s, int start, int count,

int after) {

System.out.println("started");

// Abstract Method of TextWatcher Interface.

}

public void onTextChanged(CharSequence searchcontact, int start,

int before, int count) {

System.out.println("sssssssssss"+searchcontact);

String a=searchcontact.toString();

System.out.println("casted "+a);

String[] parts = a.split(" ");

String lastWord = parts[parts.length - 1];

System.out.println("------------------------------"+lastWord);

// String lastWord = a.substring(a.lastIndexOf(" ")+1);

// System.out.println("lastword"+lastWord);

if(a.equals("p"))

{

try {

email.getText().delete(email.getSelectionEnd() - 1, email.getSelectionStart());

} catch (Exception e) {

try {

email.getText().delete(email.length() - 1, email.length());

} catch (Exception myException) {

//textfield.getText().delete(textfield.length(), textfield.length() - 1);

}

}

// Method User For Sort Out THE Words

// in

// The SearchBar

}

}

});

这里的代码时,文本更改我试图让字符串中的最后一个字,但我没有尽到this.used

字符串A = searchcontact.toString(); System.out.println(“casted”+ a); String [] parts = a.split(“”); String lastWord = parts [parts.length - 1];

获得的最后一个字,但它打印在的EditText整个字符串我怎么能做到这一点,请帮助

2012-10-23

Ramz

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值