Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've got it! I scoured the internet forever, and put a few things together to get it to work. Basically what it does is runs a parallel process that will be constantly running while the user has their focus on the particular edittext box. It will set a filter so that the user can only enter 0-5 in the first integer slot, but will be allowed to enter 0-9 for the second. This will obviously give 0-59 instead of 1-60, but that's what you want for seconds anyways. This code goes before the onCreate method, inside of your class:</p> <pre><code>final InputFilter filter = new InputFilter() { public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dent) { for (int i = start; i &lt; end; i++) { if ((source.charAt(start) == "6".charAt(0)) || (source.charAt(start) == "7".charAt(0)) || (source.charAt(start) == "8".charAt(0)) || (source.charAt(start) == "9".charAt(0)) || (!Character.isDefined(source.charAt(i))) ) { return ""; } } return null; } }; private class FilterCheckerTask extends AsyncTask&lt;Void, Void, Void&gt; { @Override protected Void doInBackground(Void... params) { while(true) { if (&lt;EditText&gt;.getText().toString().isEmpty()) { Log.e("empty","empty"); &lt;EditText&gt;.setFilters(new InputFilter[]{filter, new InputFilter.LengthFilter(2)}); } else if (&lt;EditText&gt;.getText().toString().charAt(0) &gt;= "6".charAt(0)) { Log.e("front num bad","greater than 5"); &lt;EditText&gt;.setFilters(new InputFilter[]{filter, new InputFilter.LengthFilter(2)}); } else { Log.e("unfiltered", "unfiltered"); &lt;EditText&gt;.setFilters(new InputFilter[]{new InputFilter.LengthFilter(2)}); } if (kicker) { return null; } } } } </code></pre> <p>Then, within the <code>onCreate</code> method:</p> <pre><code> Time_sec.setOnFocusChangeListener(new OnFocusChangeListener() { public void onFocusChange(View v, boolean hasFocus) { new FilterCheckerTask().execute(); if(!hasFocus) {kicker = !hasFocus;} } }); </code></pre> <p>As I said in the first part, this will make it so the user can only input numbers between 00 and 59 in your edittext box. I know it may look a little sloppy, and it can probably be cleaned up a bit in some of the if statements, but as far as I can tell it works absolutely perfectly, and doesn't seem to slow the system at all. Hope this helps you, and if not, the future googlers.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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