auto Focus Show Soft Input - Android User Interface

Android examples for User Interface:Input Method

Description

auto Focus Show Soft Input

Demo Code


//package com.java2s;
import android.content.Context;

import android.os.Handler;

import android.view.View;
import android.view.inputmethod.InputMethodManager;

public class Main {

    public static void autoFocusShowSoftInput(View v, final Context context) {
        v.setFocusable(true);//from  w  ww.  j  a v  a  2s.c o  m
        v.setFocusableInTouchMode(true);
        v.requestFocus();
        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                showSoftInput(context);
            }
        }, 830);
    }

    public static void showSoftInput(Context context) {
        InputMethodManager imm = (InputMethodManager) context
                .getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
    }
}

Related Tutorials