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 8078195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:42:51+00:00 2026-06-05T15:42:51+00:00

I am facing problem while setting focus in EdiText. Below is my EditText property.

  • 0

I am facing problem while setting focus in EdiText. Below is my EditText property.

              <EditText
                    android:id="@+id/gatekeeperDetailedtUnitNo"
                    android:layout_width="270dip"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/gatekeeperDetailtxtUnitNo"
                    android:layout_marginTop="10dip"
                    android:hint="@string/unit_number"
                    android:inputType="number"
                    android:maxLength="8"
                    android:lines="1" />

Now I have added ‘-‘ after 6 digits. For that I have implemented TextWatcher.

 edtUnitNo.addTextChangedListener(new TextWatcher() {

        /**
         * This method is used to change charSequence when user enter more
         * then 6 character.
         */
        public void onTextChanged(CharSequence s, int start, int before,
                int count) {
            if (count < 7) {
                if (s.toString().contains("-")) {
                    Log.e(TAG, "< 7 Called");
                    String[] st1;
                    st1 = s.toString().split("-");
                    String st2 = st1[0];
                    edtUnitNo.setText(st2);
                    edtUnitNo.requestFocus();
                    edtUnitNo.requestFocus(EditText.FOCUS_RIGHT);
                }
            }
            if (edtUnitNo.getText().toString().length() == 7) {
                Log.e(TAG, "== 7 Called");
                String s1 = edtUnitNo.getText().toString();
                String s2 = s1.substring(0, 6);
                char s3 = s.charAt(6);
                edtUnitNo.setText(s2 + "-" + s3);
            }
        }

        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {

        }

        public void afterTextChanged(Editable s) {

        }
    });

Eg. My EditText value looks like “123456-7”.
I am facing issue when I have added 7 digits along with ‘-‘. When I am trying to delete the last character ‘7’, the focus come to the 0th position.

But I want to make focus at last deleted character position(after 6).

  • 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-05T15:42:53+00:00Added an answer on June 5, 2026 at 3:42 pm

    put edtUnitNo.setSelection(edtUnitNo.getText().length()); in afterTextChanged function ……..

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

Sidebar

Related Questions

I am new to Android development and facing a problem while using AndEngine. I
im new to android gaming and started andengine and facing problem while using createTiledFromAsset
I am facing problem while setting the backGround Image of LinearLayout from asset folder.
I am facing problem while generating CAB file. I want to customize the INF
I am facing a problem while creating a static cursor in DB2. This is
I'm facing a problem while deleting a record that is referenced by another table.
I am facing a problem while disabling the command button after one click. I
I am facing the problem while inserting data this way. How to insert data
I'm currently facing a weird problem while executing a command from my bash script.
Am facing a problem, while creating components through TOM API using .NET/COM Interop. Actual

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.