android - 小键盘符号在单击时未输入
问题描述
我创建了一个基于表单的应用程序。有一个表单,我在其中创建了 EditText,用于以编程方式输入数字数据。我已成功打开小键盘。但是当我单击小键盘中存在的任何符号(如 .、+ 等)时,它们不会在 EditText 中输入。这是我的示例代码,
edtValue=new EditText(SuperUserAddStudentActivity.this);
edtValue.setBackground(ContextCompat.getDrawable(SuperUserAddStudentActivity.this, R.drawable.edt_parameter_background));
edtValue.setSelected(false);
edtValue.setPadding(EditTextPaddingLeft,EdittextPaddingTop,EditTextPaddingRight,EditTextPaddingBottom);
// TODO: 16/8/18 change here
final RelativeLayout.LayoutParams edtValueLayoutParams=new RelativeLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, iParameterEditTextHeight);
edtValueLayoutParams.setMargins(0,ParameterMarginTop,0,0);
// edtValueLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
edtValue.setLayoutParams(edtValueLayoutParams);
edtValue.setInputType(InputType.TYPE_CLASS_NUMBER);
edtValue.setHint(p.getName());
edtValue.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
p.setEnteredValueByUser(s.toString());
}
@Override
public void afterTextChanged(Editable s) {
}
});
}
//add it to same layout
llTempHolder.addView(tvParameterLabel);
if(edtValue!=null)
{
llTempHolder.addView(edtValue);
}
请在这方面帮助我。我不知道为什么会这样。
解决方案
我想问题是你的 TextChangedListener。您有 3 个函数在更改文本时调用,但没有一个函数更改 edtValue 的文本值。
在 onTextChanged 尝试类似: edtValue.setText(s.toString());
我不确定自己,但不幸的是,我没有足够的声誉发表评论
推荐阅读
- apache-kafka - Flink Kafka Sink org.apache.kafka.common.errors.UnsupportedVersionException ERROR
- performance - 如何计算网速?
- javascript - 如何使用 redux-toolkit 中的 createSlice 方法在不同的 reducer 函数中使用单个动作类型
- android - 如果我在 AndroidManifest.xml 中进行更改,我应该如何为应用应用更改?
- c++ - Boost Spirit X3:跳过什么都不做的解析器
- swupdate - 如何对 swupdate Web 界面实施身份验证(用户/密码)
- java - Java binarySearch 找不到所有字符
- python - 为什么我的代码返回随机字母标记,而不是单词标记?
- java - 将 node.js 应用程序作为依赖项添加到 java maven 项目
- c - else if 和 else {if} 的区别