Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7691125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:33:05+00:00 2026-05-31T20:33:05+00:00

Please someone can explain to me the purpose of the source and dest parameters

  • 0

Please someone can explain to me the purpose of the source and dest parameters in android.text.InputFilter#filter?

I tried to read the docs but I am really confused. I am trying to use a regex to make an IP mask. Any help is appreciated.

I get it now. So, for example, if I have 123.42, then the user types 123.42d, I will have:

dest = 123.42  
source = 123.42d  
start = 5  
end = 6

InputFilter[] filters = new InputFilter[1];
    filters[0] = new InputFilter() 
    {
        public CharSequence filter(CharSequence source, int start, int end, Spanned  dest, int dstart, int dend) 
        {               
            String destTxt = dest.toString();
            String resultingTxt = destTxt.substring(0, dstart) +                           source.subSequence(start, end) + destTxt.substring(dend);                

            if(resultingTxt.equals("")) return "";

            int lastChar = resultingTxt.length() -1;

            if(String.valueOf(resultingTxt.charAt(lastChar)).matches("[^0-9.]"))
            {
                return "";
            }

            return null;
        }
    };

This isn’t working though. Shouldn’t this return me only the digits? It happens that depending on what the user type it returns me characters too.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T20:33:06+00:00Added an answer on May 31, 2026 at 8:33 pm

    If you have an EditText and you assign an InputFilter to it, then everytime you change the text in there the filter() method will be called. Much like the onClick() method of a button.

    Let’s say you had the text “Hello Androi” in your EditText before editing it. If you press
    the D key on your virtual keyboard then the inputfilter is triggered and basically asked if it is ok to add a d.

    In that case source is “Android”, start is 6, end is 7 – That is your reference to the new Text.

    dest would be “Androi” and refers to the old text in your EditText

    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 d) 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.

    If the new text is ok as is return null, if you want to skip a change return empty String (""), otherwise return the characters that replace the change.

    So a simple example might be that:

    /**
     * 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;
        }
    }
    

    It’s replacing every change with the uppercase version of it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone please explain the purpose of double-negating the reverse var in the below
Can someone please explain how Read/Show works.. I cannot find any tutorials on it.
Can someone please explain how to read the below code to find last column
Can someone please explain the following code? Source: Arrays.class, public static <T> void sort(T[]
I'm not quite sure what the purpose of session_names is.. Can someone please explain
Can someone please explain why ?___SID=U is appearing in some Magento URLs on my
Can someone please explain to me how this responsive approach works? This was done
Can someone please explain to me why the hell? When I try to set
Can please someone explain to me or bring me on the way how to
Can someone please explain this phenomenon? I am using Mojarra 2.1.6 - Glassfish 3.1.2.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.