Show keyboard automatically

Please explain me the issue about soft keyboard. For example, I have an EditText on my activity or dialogfragment or fragmentactivity, whatever. here it is:

    android:inputType="textPassword" >

    <requestFocus />

When it shows for the first time I do not see the soft keyboard and have to press editText for it to receive focus and the keyboard appears. Another activities are different, when it appears on screen the keyboard are loaded without any help. I thought that

< requestFocus />

means that EditText will be focused and keyboard will appear, but I am wrong.

How should I manage what component will receive focus and keyboard will automatically appear.


I think it's a bug or a feature which tries to present the whole activity to you without obscuring it with the soft keyboard at first. I've searched once for information regarding that but unfortunately found nothing coming from a really reliable source.

Anyway, to show the soft keyboard you can do this:

EditText editText = (EditText)findViewById(;
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);

I've also seen this code that should force the soft keyboard to become visible just after activity start, but never tried it:

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);

And if you want to hide soft keyboard you can do this:

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);

Hope that helps.


For a DialogFragment this should work: in the onCreateView() method do this:

public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_id, container);
    EditText editText = (EditText)view.findViewById(;

    // show soft keyboard

    return view;

Open the Android Manifest file.

Look for the activity tag like this

        android:windowSoftInputMode="stateVisible"       //Add this line    
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />

Add the line android:windowSoftInputMode="stateVisible" as shown above

I know this has already been answered, but I found a way to do the accepted answer in onCreateDialog instead of just in onCreateView. When you finish with the builder, before you return do the following:

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());  
// blah blah blah do builder stuff here like setTitle, setView, etc

Dialog d = builder.create();

Here's the important part:

return d;

add to onCreate or onStart();


Try this

public void onResume() {
   final View v = getDialog().findViewById(; Runnable() {
      public void run() {
        InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
        if (imm != null) imm.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT);

This is what worked for me -

Create your own EditText class and override following method -

public class FocussableEditText extends EditText {

    public FocussableEditText(Context context) {

    public FocussableEditText(Context context, AttributeSet attrs) {
        super(context, attrs);

    public FocussableEditText(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

    public void onWindowFocusChanged(boolean hasWindowFocus) {
        if (hasWindowFocus) {
            InputMethodManager imm = (InputMethodManager)getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(this, InputMethodManager.SHOW_FORCED);

I Recommend the following link, i was followed the steps which is mentioned below link, perfectly working, it's pretty good answer, done in very simple steps. credit goes to answered person. hope it will helps the person who mess-up with keyboard popup on dialog activity.

DialogFragment and force to show keyboard

for me by adding this line android:windowSoftInputMode="stateVisible" in your manifest like this


this is how I solved it

This is what I did and it works nice...

You can use the


anywhere across your code

public final class Utilities {

  // Shows the soft keyboard. V on which view (typically EditText) to focus the keyboard input
  public static void showSoftKeyboard(Activity activity, EditText editText) 
      InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
      imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED);

 * Called when user clicks/touches the search button
 * @param v The clicked/touched view (EditText)
protected void onSearchButtonClick(View v)
    EditText seekTopic = (EditText) findViewById(;



method belongs to the activity, which hold the EditView which I want to edit and therefore I need the soft keyboard..


Need Your Help

@import "Unexpected '@' in program"

ios ios7 xcode5

I updated project to Xcode 5 and enabled modules in build settings.

Rename specific column(s) in pandas

python pandas dataframe rename

I've got a dataframe called data. How would I rename the only one column header? For example gdp to log(gdp)?