Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you have an <code>EditText</code> and you assign an <code>InputFilter</code> to it, then everytime you change the text in there the <code>filter()</code> method will be called. Much like the <code>onClick()</code> method of a button.</p> <p>Let's say you had the text "Hello Androi" in your EditText before editing it. If you press the <code>D</code> key on your virtual keyboard then the inputfilter is triggered and basically asked if it is ok to add a <code>d</code>.</p> <p>In that case <code>source</code> is "Android", start is 6, end is 7 - That is your reference to the new Text.</p> <p><code>dest</code> would be "Androi" and refers to the old text in your <code>EditText</code></p> <p>So you get the new String and a position in that string (the 6,7) that you have to check if it is okay. If you would just get a single character (like the <code>d</code>) you could not decide if e.g. the number you just entered forms an ip adress. You need the whole text as a context in some cases.</p> <p>If the new text is ok as is return <code>null</code>, if you want to skip a change return empty String (<code>""</code>), otherwise return the characters that replace the change.</p> <p>So a simple example might be that:</p> <pre><code>/** * Simplified filter that should make everything uppercase * it's a demo and will probably not work * - based on InputFilter.AllCaps */ public static class AllCaps implements InputFilter { public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { // create a buffer to store the edited character(s). char[] v = new char[end - start]; // extract the characters between start and end into our buffer TextUtils.getChars(source, start, end, v, 0); // make the characters uppercase String s = new String(v).toUpperCase(); // and return them return s; } } </code></pre> <p>It's replacing every change with the uppercase version of it.</p>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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