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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:13:03+00:00 2026-05-27T19:13:03+00:00

I designed a layout for a create account activity. when one EditText loses focus,

  • 0

I designed a layout for a create account activity.

when one EditText loses focus, I’m doing some checking on the input and if something is not right I want to regain the focus on that EditText.

I already saw some questions about this, but its not working for me (or I’m doing something wrong).

when I touch on a different EditText which triggers the requestFocus(), the focus remains on the current EditText and another focus icon is shown in the EditText which requeted the focus.

help please

here’s my layout file:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res/com.cellap.tq"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:focusable="true" 
android:focusableInTouchMode="true"
android:background="@drawable/create_account_background" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:focusable="true" 
    android:focusableInTouchMode="true"
    android:layout_marginTop="70dp"
    android:layout_marginLeft="5dp"
    android:layout_marginRight="10dp">

    <TextView 
        android:id="@+id/userTextView"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:textColor="#F4DFA7"
        android:layout_marginRight="5dp"
        android:text="Username"
        android:gravity="right"
        android:layout_gravity="center_vertical"/>

    <EditText
        android:id="@+id/userEditText"
        android:inputType="text|textEmailAddress"
        android:layout_width="fill_parent"

        android:layout_height="30dp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:maxLength="64"
        android:background="@drawable/edit_text"
        android:layout_gravity="center_vertical|right"
        android:textColor="@android:color/white">

    </EditText>
</LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:focusable="true" 
        android:focusableInTouchMode="true" 
        android:layout_marginTop="5dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="10dp">

        <TextView 
            android:id="@+id/passTextView"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:textColor="#F4DFA7"
            android:layout_marginRight="5dp"
            android:gravity="right"
            android:text="Password"/>

        <EditText
            android:id="@+id/passEditText"
            android:layout_width="fill_parent"
            android:layout_height="30dp"

            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:maxLength="30"
            android:layout_gravity="center_vertical"
            android:inputType="textPassword"
            android:textColor="@android:color/white"
            android:background="@drawable/edit_text">


        </EditText>
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:focusable="true" 
        android:focusableInTouchMode="true"
        android:layout_marginTop="5dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="10dp">

        <TextView 
            android:id="@+id/passConfirmTextView"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:textColor="#F4DFA7"
            android:layout_marginRight="5dp"
            android:gravity="right"
            android:text="Confirm password"/>

        <EditText
            android:id="@+id/passConfirmEditText"
            android:layout_width="fill_parent"
            android:layout_height="30dp"

            android:layout_gravity="center_vertical"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:maxLength="30"
            android:inputType="textPassword"
            android:background="@drawable/edit_text"
            android:textColor="@android:color/white">


        </EditText>
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:focusable="true" 
        android:focusableInTouchMode="true"
        android:layout_marginTop="5dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="10dp">

        <TextView 
            android:id="@+id/emailTextView"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:textColor="#F4DFA7"
            android:layout_marginRight="5dp"
            android:gravity="right"
            android:text="Email"/>

        <EditText
            android:id="@+id/emailEditText"
            android:layout_width="fill_parent"
            android:layout_height="30dp"

            android:layout_gravity="center_vertical"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:maxLength="255"
            android:scrollHorizontally="false" 
            android:inputType="textEmailAddress"
            android:background="@drawable/edit_text"
            android:textColor="@android:color/white">


        </EditText>
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" 
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:layout_marginTop="5dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="10dp">

        <TextView 
            android:id="@+id/confirmEmailTextView"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:textColor="#F4DFA7"
            android:layout_marginRight="5dp"
            android:gravity="right"
            android:text="Confirm email"/>

        <EditText
            android:id="@+id/confirmEmailEditText"
            android:layout_width="fill_parent"
            android:layout_height="30dp"

            android:layout_gravity="center_vertical"
            android:maxLength="255"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:inputType="textEmailAddress"
            android:background="@drawable/edit_text"
            android:textColor="@android:color/white">


        </EditText>
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" 
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:layout_marginTop="5dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="10dp">

        <TextView 
            android:id="@+id/signupTextView"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:textColor="#F4DFA7"
            android:layout_marginRight="5dp"
            android:gravity="right"
            android:text="Sign up:"/>

        <TextView 
            android:id="@+id/signUpText"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:textColor="#FF0000"
            android:paddingRight="5dp"

            />



    </LinearLayout>


    <com.cellap.tq.ButtonView
        android:id="@+id/create_btn"
         android:layout_width="216dp"
        android:layout_height="49dp"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="30dp"
        android:focusable="true"
        android:focusableInTouchMode="true"
        custom:button="create_btn"/>


    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:orientation="horizontal"
        android:layout_marginTop="15dp"
        android:layout_marginBottom="5dp"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp">

        <Button 
            android:id="@+id/fbconnect_btn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:layout_marginRight="5dp"
            android:background="@drawable/fbconnect_btn"/>

    </LinearLayout>

in the code I do like that:

final EditText userEditText = (EditText)findViewById(R.id.userEditText);

    userEditText.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if(!hasFocus){
                Log.i(TAG, "userEditText lost focus");

                m_userName = userEditText.getText().toString();
                if(m_userName.length() < 6){
                    m_signUpText.setText("Username should have at least 6 characters");
                    userEditText.requestFocus();
                }
                else{
                    checkUserNameExists();
                }

            }
        }
    });
  • 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-27T19:13:04+00:00Added an answer on May 27, 2026 at 7:13 pm

    found a solution here

    This solution works (no need to add android:focusable=”true”\android:focusableInTouchMode=”true”):

    final EditText userEditText = (EditText)findViewById(R.id.userEditText);
    
    userEditText.setOnFocusChangeListener(new OnFocusChangeListener() {
    
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if(!hasFocus){
                Log.i(TAG, "userEditText lost focus");
                if(null == m_requestFocus){
                    m_userName = userEditText.getText().toString();
                    if(m_userName.length() < 6){
                        m_signUpText.setText("Username should have at least 6 characters");
                        m_requestFocus = userEditText;
                    }
                    else{
                        checkUserNameExists();
                    }
                }
            }
            else{
                if(null != m_requestFocus & m_requestFocus != userEditText){
                    v.clearFocus();
                    m_requestFocus.requestFocus();
                    m_requestFocus = null;
                }
            }
        }
    });
    

    To clarify the problem:

    User edits EditText A -> user touch EditText B to edit it -> EditText A onFocusListener.onFocusChanged is called -> EditText A requestFocus -> EditText B still has the focus and typing any text, writes to its edit text. only a marker of focus, appears on EditText A.

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

Sidebar

Related Questions

I have a doubt in layouts.I have designed one layout using group layout using
I have designed my layout and on smaller phone screens not everything is visible,
I have a poorly designed database. One of the most important tables has 11,000+
Here's a tricky one - how do I programatically create and interrogate a database
I've got a full layout designed using 960.gs and am wanting to use it
I am interested to create a drag-and-drop layout designer using only JavaScript, HTML and
I designed a pretty cool looking form layout but have no clue how to
I developed a Sitecore control I'd like to put into a layout on one
In javafx 2.0 it is possible to create the layout by using FXML approach
I have an activity designed to get customer information. First line gets name, 2nd

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.