我尝试使用TextChangedListener,beforeTextChanged和afterTextChanged!但我没有结果
答案 0 :(得分:1)
TextWatcher
课程可以帮助您:
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int a, int b, int c) {
// TODO Auto-generated method stub
output.setText(s);
if(a == 9){
Toast.makeText(getApplicationContext(), "Maximum Limit Reached", Toast.LENGTH_SHORT).show();
}
}};
答案 1 :(得分:0)
这项工作对我来说:)
txtwt = new TextWatcher()
{
char last ;
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after)
{
if (s.toString().length() >= 1)
EntredNumber = s.toString();
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count)
{
if (s.toString().length() >= 2)
{
last = (s.toString().charAt(s.toString().length() - 1));
// Toast.makeText(getApplicationContext(), last +"", Toast.LENGTH_SHORT).show();
if (EntredNumber.contains((last + "")))
{
txtImputNumber.removeTextChangedListener(txtwt);
txtImputNumber.setText(EntredNumber);
txtImputNumber.setSelection(EntredNumber.length());
txtImputNumber.addTextChangedListener(txtwt);
}
}
}
@Override
public void afterTextChanged(Editable s)
{
}
};
txtImputNumber.addTextChangedListener(txtwt);