I tried with Using TextChangedListener, beforeTextChanged and afterTextChanged! but I had no result
Asked
Active
Viewed 82 times
0
-
So you want to make it so you cannot enter, for example, 9 twice? – Coova Mar 19 '15 at 16:13
-
ItzHoudini yes exactly – Chawki Messaoudi Mar 19 '15 at 16:15
-
1textwatcher is the right approach. Can you share your code? – bond Mar 19 '15 at 16:16
2 Answers
1
TextWatcher
class can help you:
@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();
}
}};

Mohammad Arman
- 7,020
- 2
- 36
- 50
0
this work for me :)
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);

Chawki Messaoudi
- 714
- 2
- 6
- 18