Wednesday, February 19, 2014

When EditText null value, EditText but can not get the focus and the soft keyboard popups


EditText no value is to ask how to get the focus of the pop-up soft keyboard?

As the registration page first loads do not want to start a soft keyboard and focus! So I'm all EditText parent added
 
android: focusable = "true"
android: focusableInTouchMode = "true"


Do not get the focus and the soft keyboard pop up to load.

I hope to fill in the following information to determine the value of each EditText, in the absence of input values ​​EditText to give it focus soft keyboard pops up!
The following is my approach:
 
public class Reg extends Activity implements OnClickListener {
private Dialog dialog;
String mc ;/ / Name
String u ;/ / username

EditText u_mingcheng, u_user;

protected void onCreate (Bundle savedInstanceState) {
/ / TODO Auto-generated method stub
super.onCreate (savedInstanceState);
setContentView (R.layout.reg);
/ /
u_mingcheng = (EditText) findViewById (R.id.u_mingcheng);
u_user = (EditText) findViewById (R.id.u_user);


 
private void reg () {
mc = u_mingcheng.getText () toString ();.
u = u_user.getText () toString ();.


if (u_mingcheng.length () == 0 | | u_user.length () == 0) {

if (u_mingcheng.length () == 0) {
u_mingcheng.requestFocus () ;/ / get the focus
u_mingcheng.requestFocusFromTouch ();
System.out.println ("1");
}

return;

}


These are part of the code!

System.out.println ("1"); has executed, but u_mingcheng get less focus and play the keyboard.<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Why would a person have not answered my ah! Thank Kazakhstan

Reply:
Obtain input focus and pop should not the same thing and you call this method in which it is placed on the main thread
Reply:
Yes! In the main UI thread inside.
Reply:
UI painting is not completed before obtaining the focus is invalid, so do not take reg on oncreate method inside or delayed a few seconds to perform.

No comments:

Post a Comment