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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:51:07+00:00 2026-05-25T09:51:07+00:00

Possible Duplicate: How do you close/hide the Android soft keyboard programmatically? First thing first

  • 0

Possible Duplicate:
How do you close/hide the Android soft keyboard programmatically?

First thing first I already saw this thread. I tried the accepted methods given there, but nothing worked for me.

I have two screens in my app.

  • First one has 2 EditText – One for username and one for password
  • Second one have one ListView, and an EditText – to filter the
    listView

In my first screen, I want username EditText to have focus on startup and the Keyboard should be visible. This is my implementation (simplified by removing unnecessary/unrelated code).

#app_login.xml

<LinearLayout android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:paddingLeft="20dip"  
    android:paddingRight="20dip">

    <EditText android:id="@+id/username" 
        android:singleLine="true" 
        android:layout_width="fill_parent"  
        android:layout_height="wrap_content" android:hint="Username"  
        android:imeOptions="actionDone" android:inputType="text"
        android:maxLines="1"/>

    <EditText android:id="@+id/password" 
        android:password="true" 
        android:singleLine="true"  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"    
        android:hint="Password" />
</LinearLayout>

#AppLogin.java

class AppLogin extends Activity{
    private EditText mUserNameEdit = null;
    private EditText mPasswordEdit = null;

    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.app_login);
        
        mUserNameEdit  =    (EditText) findViewById(R.id.username);
        mPasswordEdit  =    (EditText) findViewById(R.id.password);

        /* code to show keyboard on startup.this code is not working.*/
        InputMethodManager imm =  (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(mUserNameEdit, InputMethodManager.SHOW_IMPLICIT);
    
    }//End of onCreate()
}

Well, the keyboard is not showing at startup. And my design badly requires a keyboard there.

Now on to second page. As I already mentioned, I have a listView and EditText there. I want my keyboard to be hidden on startup only to appear when the user touches the editText. Can you believe it? whatever I tried soft Keyboard is showing when I load the activity. I am not able to hide it.

#app_list_view.xml

<LinearLayout android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" >
    
   <EditText android:id="@+id/filter_edittext"       
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:hint="Search" android:inputType="text" 
        android:maxLines="1"/>
    <ListView android:id="@id/android:list" 
        android:layout_height="fill_parent"
        android:layout_weight="1.0" 
        android:layout_width="fill_parent" 
        android:focusable="true" 
        android:descendantFocusability="beforeDescendants"/>
</LinearLayout>     

#AppList.java

public class MyListActivity extends ListActivity{
   private EditText mfilterEditText;

    @Override
   public void onCreate(Bundle savedInstanceState) {        
      super.onCreate(savedInstanceState);
      setContentView(R.layout.app_list_view);

      mFilterEditText  =  (EditText) findViewById(R.id.filter_edittext);
      InputMethodManager imm = InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
      imm.hideSoftInputFromWindow(mFilterEditText.getWindowToken(), 0);
   }
}

To simplify

  1. On Login Page (first Page) I want my keyboard to be visible on startup.
  2. On SecondPage I want the keyboard to be hidden first, only to appear
    when the user touches editText

And my problem is I am getting the exact opposite on both occasions. Hope someone faced this issue before. BTW I am testing on the simulator and HTC Desire phone.

#FINAL OUTCOME

Well, I got it working, with the help of all my friends here.

1. To Show keyboard on startup

Two answers worked for me. One provided by @CapDroid, which is to use a handler and post it delayed..

mUserNameEdit.postDelayed(new Runnable() {
  @Override
  public void run() {
    // TODO Auto-generated method stub
    InputMethodManager keyboard = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
    keyboard.showSoftInput(mUserNameEdit, 0);
  }
},50);

The second answer is provided by @Dyarish, In fact, he linked to another SOF thread, which I haven’t seen before. But the funny thing is that this solution is given in the thread which I referenced at the start. And I haven’t tried
it out because it had zero votes in a thread where all other posts have plenty of votes. Height of foolishness.

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

For me, the second solution looked neat, so I decided to stick with it..But the first one certainly works.
Also, @Dyarish’s answer contains a clever hack of using a ScrollView below EditText to give EditText the focus. But I haven’t tried it, but it should work. Not neat though.

2. To hide keyboard at activity start

Only one answer worked for me, which is provided by @Dyarish. And the solution is to use
focusableInTouchMode settings in XML for the layout containing the EditTexts. This did the trick

<LinearLayout android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:focusableInTouchMode="true">
    <EditText android:id="@+id/filter_edittext"       
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:hint="Search" android:inputType="text" 
        android:maxLines="1"/>
    <ListView android:id="@id/android:list" 
        android:layout_height="fill_parent"
        android:layout_weight="1.0" 
        android:layout_width="fill_parent" 
        android:focusable="true" 
        android:descendantFocusability="beforeDescendants"/>
</LinearLayout> 

Anyway, I end up using Dyarish’s answer in both cases. So I am awarding the bounty to him. Thanks to all my other friends
who tried to help me.

  • 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-25T09:51:08+00:00Added an answer on May 25, 2026 at 9:51 am

    Adding this to your code android:focusableInTouchMode="true" will make sure that your keypad doesn’t appear on startup for your edittext box. You want to add this line to your linear layout that contains the EditTextBox. You should be able to play with this to solve both your problems. I have tested this. Simple solution.

    ie: In your app_list_view.xml file

    <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:orientation="vertical" 
        android:focusableInTouchMode="true">
        <EditText 
            android:id="@+id/filter_edittext"       
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:hint="Search" 
            android:inputType="text" 
            android:maxLines="1"/>
        <ListView 
            android:id="@id/android:list" 
            android:layout_height="fill_parent"
            android:layout_weight="1.0" 
            android:layout_width="fill_parent" 
            android:focusable="true" 
            android:descendantFocusability="beforeDescendants"/>
    </LinearLayout> 
    

    —————— EDIT: To Make keyboard appear on startup ———————–

    This is to make they Keyboard appear on the username edittextbox on startup. All I’ve done is added an empty Scrollview to the bottom of the .xml file, this puts the first edittext into focus and pops up the keyboard. I admit this is a hack, but I am assuming you just want this to work. I’ve tested it, and it works fine.

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
        android:orientation="vertical" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:paddingLeft="20dip"  
        android:paddingRight="20dip">
        <EditText 
            android:id="@+id/userName" 
            android:singleLine="true" 
            android:layout_width="fill_parent"  
            android:layout_height="wrap_content" 
            android:hint="Username"  
            android:imeOptions="actionDone" 
            android:inputType="text"
            android:maxLines="1"
           />
        <EditText 
            android:id="@+id/password" 
            android:password="true" 
            android:singleLine="true"  
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android:hint="Password" />
        <ScrollView
            android:id="@+id/ScrollView01"  
            android:layout_height="fill_parent"   
            android:layout_width="fill_parent"> 
        </ScrollView>
    </LinearLayout>
    

    If you are looking for a more eloquent solution, I’ve found this question which might help you out, it is not as simple as the solution above but probably a better solution. I haven’t tested it but it apparently works. I think it is similar to the solution you’ve tried which didn’t work for you though.

    Hope this is what you are looking for.

    Cheers!

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

Sidebar

Related Questions

Possible Duplicate: Cross-thread operation not valid I am trying to close the base of
Possible Duplicate: Android: How to kill an application with all it's activities? I tried
Possible Duplicate: How to programmatically close a JFrame I am developing a java GUI
Possible Duplicate: Keyboard shortcut to close all tabs but current one in Visual Studio?
Possible Duplicate: How do I calculate someone's age in C#? Maybe this could be
Possible Duplicate: close mysql connection important? How important is it close an mysql connection
Possible Duplicate: Close and Dispose - which to call? Hi, After reading some web
Possible Duplicate: Remove close button on jQueryUI Dialog? I am getting some problem to
Possible Duplicate: Remove close button on jQueryUI Dialog? I'm trying to make a dialog
Possible Duplicate: Should one call .close() on HttpServletResponse.getOutputStream()/.getWriter()? Am I responsible for closing the

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.