Note that there are some explanatory texts on larger screens.

plurals
  1. POValidate EditText
    primarykey
    data
    text
    <p>I've stucked with the following problem: I need to validate, that EditText's value is an Integer between 1 and 1000. If it's not - I should put some of the default value into the EditText. When I try to do such a thing with following code - I get to the infinite loop (well, that was predictable). I've checked the similar questions, but I still can't figure out, how to make the code working.<BR>Are there any other ways to implement the desirable behaviour? How I should edit my code to achieve this?<BR></p> <pre><code> Long mailIntervalValue; EditText etMailInterval; . . . . etMailInterval=(EditText)findViewById(R.id.et_mail_check_interval); etMailInterval.setText(mailIntervalValue.toString()); etMailInterval.addTextChangedListener(new TextWatcher(){ public void afterTextChanged(Editable s) { Integer t=Integer.getInteger(s.toString()); if (t==null){ s.clear(); s.append(mailIntervalValue.toString()); mailIntervalValue=MessageManager.DEFAULT_TIME; } else mailIntervalValue=t.longValue(); if (mailIntervalValue&lt;1 || mailIntervalValue&gt;1000){ if (mailIntervalValue&lt;1) mailIntervalValue=1L; else mailIntervalValue=1000L; s.clear(); s.append(mailIntervalValue.toString()); Toast.makeText(MainActivity.this, MainActivity.this.getString(R.string.settings_timer_fail), Toast.LENGTH_SHORT).show(); } saveMailerPrefs(); } public void beforeTextChanged(CharSequence s, int start, int count, int after){} public void onTextChanged(CharSequence s, int start, int before, int count){} }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload