My code for opening an input dialog reads as follows:
final AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle(\"Dialog Title\");
If you want to pop up dialog box along with soft key pad, so that user could free from tap on edit text inside dialog to show keypad, for example if you are going to take some value from dialog box, then use this simple code, it will solve your problem.
public void onClick(final View v)
{
AlertDialog.Builder alert = new AlertDialog.Builder(v.getContext());
alert.setIcon(R.drawable.smsicon);
alert.setTitle(" Secrete Code");
alert.setMessage("Enter a Key for secrete text !");
final EditText shft_val = new EditText(v.getContext());
shft_val.setInputType(InputType.TYPE_CLASS_NUMBER);//changing the keyBoard to No only,restrict the string etc
alert.setView(shft_val);
//pOp Up the key pad on Edit Text focus event
shft_val.setOnFocusChangeListener(new OnFocusChangeListener()
{
public void onFocusChange(View arg0, boolean arg1)
{ InputMethodManager inputMgr = (InputMethodManager)v.getContext().
getSystemService(Context.INPUT_METHOD_SERVICE);
inputMgr.toggleSoftInput(InputMethodManager.SHOW_FORCED,InputMethodManager.HIDE_IMPLICIT_ONLY);
}
});
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int whichButton)
{
//Your specific code...
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
return;
}
});
alert.show();
}