I'd like to create a Dialog Box where the user can insert a number; so I overrided the onCreateDialog method this way:
protected Dialog onCreateDialog(int id) {
EditText editNum=new EditText(this);
editNum.setMaxLines(1);
editNum.setRawInputType(InputType.TYPE_CLASS_NUMBER);
String strVal=listViewNum.getItemAtPosition(selectedItem).toString();
strVal=strVal.substring(strVal.indexOf("=")+1,strVal.length()-1);
editNum.setText(Util.formatNumber(Double.parseDouble(strVal)));
editNum.selectAll();
editNum.setGravity(android.view.Gravity.RIGHT);
return new AlertDialog.Builder(this)
.setTitle(getString(R.string.DialogEditNumberTitle))
.setView(editNum)
.setPositiveButton("OK", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
})
.setNegativeButton("Annulla", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
})
.create();
}
But despite this I'm still allowed to insert non-numeric characters and there is no sign of the soft keyboard...what's wrong with my code?
I'm not sure what you could do programmatically, BUT you could create your own custom layout which will contain an edittext as follows:
and then in the code for the onCreateDialog: