P9p studios
P9p studios

Reputation: 69

edit text keyboard disapears on double press grrrrr

I'm making a login screen and having trouble with the edit text keyboard disappearing. The app loads, then you would enter your name in the first edit text, But sometimes it dosen't load the keyboard up. So you press it again and it dosen't show. The only way to get it to show again is by clicking the second edit text called etPassword.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Pushbots.sharedInstance().init(this);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_login);

    etUsername = (EditText) findViewById(R.id.etUsername);
    etPassword = (EditText) findViewById(R.id.etPassword);
    tvRegister = (TextView) findViewById(R.id.tvRegister);
    tvAboutus = (TextView) findViewById(R.id.tvAboutus);
    tvContact = (TextView) findViewById(R.id.tvContact);
    tvDonate = (TextView) findViewById(R.id.tvDonate);
    bLogin = (Button) findViewById(R.id.bLogin);
    cbRememberme = (CheckBox) findViewById(R.id.cbRememberme);

    etUsername.setOnClickListener(this);
    etPassword.setOnClickListener(this);
    tvRegister.setOnClickListener(this);
    tvAboutus.setOnClickListener(this);
    tvContact.setOnClickListener(this);
    tvDonate.setOnClickListener(this);
    bLogin.setOnClickListener(this);

    etUsername.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_GO) {
                // hide virtual keyboard
                InputMethodManager imm =
                    (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
                return true;
            }
            return false;
        }
    });

    etPassword.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_GO) {
                // hide virtual keyboard
                InputMethodManager imm2 =
                    (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm2.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
                return true;
            }
            return false;
        }
    });
}

Upvotes: 1

Views: 41

Answers (1)

Ivan
Ivan

Reputation: 3062

You are using

imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);

Try to remove those calls and add this

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);

in your onCreate(). This will force keyboard to appear automatically.

Upvotes: 0

Related Questions