首页 > 解决方案 > 小键盘符号在单击时未输入

问题描述

我创建了一个基于表单的应用程序。有一个表单,我在其中创建了 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);
                        }

请在这方面帮助我。我不知道为什么会这样。

标签: android

解决方案


我想问题是你的 TextChangedListener。您有 3 个函数在更改文本时调用,但没有一个函数更改 edtValue 的文本值。

在 onTextChanged 尝试类似: edtValue.setText(s.toString());

我不确定自己,但不幸的是,我没有足够的声誉发表评论


推荐阅读