开发者

Displaying Keypad

I have 2 EditText fields, and I would like to display the key pad for the second immediately after validation of the first one succeed开发者_如何学运维s (I don't want the user to tap the second field). I have tried the response here, but I can only get it to work when validation fails and the user taps OK on the error pop up:

private void showMSG( String str, final EditText txtField ) {
        
        // build pop up box with error message
        AlertDialog.Builder builder = new AlertDialog.Builder( this );
        builder.setMessage( str )
                .setTitle( "Input Error" )
                .setCancelable( false )
                .setNeutralButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) { 
                        dialog.dismiss();
                        showKeyPad( txtField );
                        //((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(txtField, 0);
                    }
                });
        
        
        AlertDialog message = builder.create();
        message.show();
    } // END showMSG() -----

The keypad does not display if validation passes and the second field still needs input:

if ( this.frameSizeLength() == 0 ) {
                    this.txtFrameSize.requestFocus();
                    // TO DO:  display keyboard
                    this.showKeyPad( this.txtFrameSize );
}

I created a method to show the keypad knowing I would need to show the keypad in more than one case:

private void showKeyPad( View v ) {
        ( (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE) ).showSoftInput(v, 0);
    } // END showKeyPad() -----

Everything sent to showKeyPad() is an EditText, and after reading Android docs, I'm still at a loss.

Thanks, MD.


    InputMethodManager imm = (InputMethodManager) Main.mainClassInstance
.getSystemService(Main.mainClassInstance.INPUT_METHOD_SERVICE);

   imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);

or

public void showKeyboard(View v) {
    InputMethodManager imm = (InputMethodManager) Main.mainClassInstance
            .getSystemService(Main.mainClassInstance.INPUT_METHOD_SERVICE);
    imm.showSoftInput(v, imm.SHOW_IMPLICIT);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜