Android keyboard cannot be started

Source: Internet
Author: User

Q: A page (with an attachment) contains a search box and a map. When a program jumps to this page, it automatically locates and displays some specified information. However, click the input box, the keyboard does not start. The cause remains unknown. It may be that the focus cannot be obtained by the input box when you jump to this page, but the configured listener can be executed and cannot be understood.
Try a solution, listen to the input box, and manually enable the keyboard. solution 1: Encapsulation Method
[Java]
KeyBoardUtil. showKeyBoard (Activity );
[Java] view plaincopy
/**
* Display the keyboard
* @ Param activity
*/
Public static void showKeyBoard (Activity activity ){
Try {
InputMethodManager imm = (InputMethodManager) activity. getSystemService (Context. INPUT_METHOD_SERVICE );
If (imm! = Null ){
View view = activity. getCurrentFocus ();
If (view! = Null ){
Imm. showSoftInputFromInputMethod (view. getWindowToken (), 0 );
Imm. toggleSoftInputFromWindow (view. getWindowToken (), 0, InputMethodManager. HIDE_NOT_ALWAYS );
}
}

} Catch (Exception e ){
}
}
This method can only be called when you enter the interface for the first time. When you jump to another interface and then return, the keyboard does not work properly.
You can directly use the following method in the listener to modify the scheme:
[Java]
InputMethodManager imm = (InputMethodManager) NearVenueActivity. this. getSystemService (Context. INPUT_METHOD_SERVICE );
Imm. toggleSoftInput (0, InputMethodManager. HIDE_NOT_ALWAYS );

This is the case that the keyboard can be restarted every time, but the keyboard blinks. The reason may be that the keyboard is restarted repeatedly, and the system determines that the keyboard is restarted again.
Finally, find the solution:
[Java]
/**
* Solve the problem that the keyboard cannot be started.
*/
EtSearchVenue. setOnTouchListener (new OnTouchListener (){
@ Override
Public boolean onTouch (View v, MotionEvent event ){
WindowManager. LayoutParams params = getWindow (). getAttributes ();
If (event. getAction () = MotionEvent. ACTION_UP &&
Params. softInputMode! = WindowManager. LayoutParams. SOFT_INPUT_STATE_VISIBLE ){
InputMethodManager imm = (InputMethodManager) NearVenueActivity. this. getSystemService (Context. INPUT_METHOD_SERVICE );
Imm. toggleSoftInput (0, InputMethodManager. HIDE_NOT_ALWAYS );
}
Return true;
}
 
});

The keyboard cannot be called in this case, but the reason is unknown.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.