没有软键盘的对话框内的EditText [英] No soft keyboard for the EditText inside the Dialog Box
本文介绍了没有软键盘的对话框内的EditText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个对话框,用户可以插入一个号码;所以我overrided的onCreateDialog方法是这样的:
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();
}
但尽管如此我还是允许插入非数字字符,也没有软键盘的迹象......有什么错我的code?
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?
推荐答案
我不知道,你可以通过编程做什么,而是你可以如下创建自己的自定义布局,将包含一个EditText:
I'm not sure what you could do programmatically, BUT you could create your own custom layout which will contain an edittext as follows:
<EditText android:id="@+id/myEditText"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:inputType="numbers"
android:digits="0123456789"/>
然后在code为onCreateDialog:
and then in the code for the onCreateDialog:
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View myLayout = inflater.inflate(R.layout.myLayout, null); //I showed this as a linear layout before, but it must be a view to inflate it
EditText myEditText = (EditText)myLayout.findViewById(R.id.myEditText);
//create myEditText listener here, if needed
dialog.setView(myLayout);
这篇关于没有软键盘的对话框内的EditText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文