添加输入类型时 EditText 崩溃
在我的 Android 应用程序中,我有一个对话框,用户在其中将信息输入到 EditText 并保存数据。到目前为止,一切工作正常,直到我将 inputType
添加到 EditTexts
中。我似乎找不到这个问题的解决方案,我对 android 编程和一般编程相当陌生,所以这可能是一个愚蠢的错误,但我无法弄清楚。这里是一些代码:
private Dialog dialog() {
Dialog diUnit = new Dialog(Overzicht.this);
diUnit.setContentView(R.layout.unitdialog);
EditText etKM = (EditText) diUnit.findViewById(R.id.etKM);
etKM.setInputType(InputType.TYPE_CLASS_NUMBER);
diUnit.setTitle("Add unit");
diUnit.setCancelable(false);
diUnit.getWindow().getAttributes().width = LayoutParams.FILL_PARENT;
bUnitDialogSave = (Button) diUnit.findViewById(R.id.bUnitDialogVoegToe);
bUnitDialogCancel = (Button) diUnit.findViewById(R.id.bUnitDialogCancel);
bUnitDialogCancel.setOnClickListener(this);
bUnitDialogAdd.setOnClickListener(this);
return diUnit;
}
和 logcat :
我知道它没有存储 EditText
尚未输入,但一旦我添加 setInputType 行,问题就开始了。
In my android application I have a dialog box in which the user inputs info into an EditText
and saves the data. Everything so far worked fine until I added an inputType
to the EditTexts
. I can't seem to find the solution to this problem, I'm rather new to android programming and programming in general so it might be a dumb mistake but I can't figure it out. Here some of the code:
private Dialog dialog() {
Dialog diUnit = new Dialog(Overzicht.this);
diUnit.setContentView(R.layout.unitdialog);
EditText etKM = (EditText) diUnit.findViewById(R.id.etKM);
etKM.setInputType(InputType.TYPE_CLASS_NUMBER);
diUnit.setTitle("Add unit");
diUnit.setCancelable(false);
diUnit.getWindow().getAttributes().width = LayoutParams.FILL_PARENT;
bUnitDialogSave = (Button) diUnit.findViewById(R.id.bUnitDialogVoegToe);
bUnitDialogCancel = (Button) diUnit.findViewById(R.id.bUnitDialogCancel);
bUnitDialogCancel.setOnClickListener(this);
bUnitDialogAdd.setOnClickListener(this);
return diUnit;
}
And the logcat :
I know it's not storing the EditText
input yet but the problem starts as soon as I add the setInputType line.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将布局
R.layout.unitdialog
膨胀为View
(使用LayoutInflater
),然后搜索该EditText 在膨胀的
View
中:Try to inflate the layout
R.layout.unitdialog
into aView
(with theLayoutInflater
) and then search for thatEditText
in the inflatedView
: