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

  • Home
  • SEARCH
  • 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 8600589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:39:02+00:00 2026-06-12T01:39:02+00:00

I have an EditText field in my app which is for person’s height. How

  • 0

I have an EditText field in my app which is for person’s height. How do I format it to make it look like say 5’9″? When a person types 5 the app should add ‘ by itself and when a person types 9 it should add “. How do I do that? Thank you.

  • 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-06-12T01:39:03+00:00Added an answer on June 12, 2026 at 1:39 am

    Use this:

    public class TextWatcherActivity extends Activity {
    
        EditText e;
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            e = (EditText) findViewById(R.id.editText1);
            e.addTextChangedListener(new CustomTextWatcher(e));
        }
    }
    
    class CustomTextWatcher implements TextWatcher {
        private EditText mEditText;
    
        public CustomTextWatcher(EditText e) {
            mEditText = e;
        }
    
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
        }
    
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    
        public void afterTextChanged(Editable s) {
            int count = s.length();
            String str = s.toString();
            if (count == 1) {
                str = str + "'";
            } else if (count == 2) {
                return;
            } else if (count == 3) {
                str = str + "\"";
            } else if (count >= 4) {
                return;
            }
            mEditText.setText(str);
                mEditText.setSelection(mEditText.getText().length());
        }
    }
    

    Edit:

    If user can insert one,two and more digit between ' and " change afterTextChanged in above code like this:

    public void afterTextChanged(Editable s) {
        int count = s.length();
        String str = s.toString();
        if (count == 1) {
            str = str + "'";
        } else if (count == 3) {
            str = str + "\"";
        } else if ((count > 4) && (str.charAt(str.length() - 1) != '\"') ){
            str = str.substring(0, str.length() - 2) + str.charAt(str.length() - 1)
            + "\"";
        } else {
            return;
        }
        mEditText.setText(str);
        mEditText.setSelection(mEditText.getText().length());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've just started writing my first app. I have EditText field in which i
I have an editText field for which I want check that it meets with
All- I have an app in which the user inputs values into multiple edittext
I have an activity that contains several user editable items (an EditText field, RatingBar,
I m using one EditText field and one spinner. I have to pass teh
My question is how can i clear the editText field after i have saved
I have an EditText for an email field. My mobile screen is really small
I have an EditText input that I would like to only allow numbers 1
I have an EditText, which generally shows parallel to the screen X-axis. I want
I have an EditText field for the user to enter their weight in lbs.

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.