Reputation: 23
I writing Android app via Xamarin (C#)
I have EditText field. And have check for NullOrEmpty.
if (string.IsNullOrEmpty (ulitsa.Text) ) {
Toast.MakeText (this, "Заполните поле 'Ваша Улица'", ToastLength.Long).Show ();
}
I want to set max and min character filters. Min-3, Max-6 ,and if user don't have this count of characters show toast notification.
How I can realize this?
Upvotes: 1
Views: 525
Reputation: 23
I solve problem
if(string.IsNullOrEmpty(kod.Text ) || kod.ToString().Length < 3 ||kod.ToString().Length > 3 )
{
Toast.MakeText (this, "Заполните поле 'Код'", ToastLength.Long).Show();
}
if(string.IsNullOrEmpty(tel.Text ) || tel.ToString().Length < 1 ||tel.ToString().Length > 7)
{
Toast.MakeText (this, "Заполните поле 'Телефон'", ToastLength.Long).Show();
}
Upvotes: 0
Reputation: 649
myEditText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
//Here, get text length:
Integer len = myEditText.getText().toString().length();
// Then, depending on the length display the toast and do what you want
}
});
But you can actually set the max length programmatically:
InputFilter[] filterArray = new InputFilter[1];
filterArray[0] = new InputFilter.LengthFilter(6);
myEditText.setFilters(filterArray);
Upvotes: 1