Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.app.Activity;

import android.view.View;

import android.view.WindowManager;

import android.widget.EditText;

public class Main {
    /**
     * Automatic showing keyboard and set focus
     * @param EditText editText
     * @param Activity activity
     */
    public static void showKeyboard(EditText editText, final Activity activity) {
        editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    activity.getWindow()
                            .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                }
            }
        });

        editText.requestFocus();
    }
}