退格时的EditText游标问题

时间:2015-01-05 18:22:12

标签: android android-edittext

我在edittext表单项上定义了一个自定义EditText类。当我对内容进行退格时,我会在字段中看到这个奇怪的多个光标。

enter image description here

我做了一个退格,直到该字段中的第一个'j',这就是它出现的方式。这是我写的自定义代码:

private class RegistrationEditText extends EditText {

    boolean required;
    private String key;
    private boolean isQuestion = false;
    private String questionKey;

    public RegistrationEditText(boolean required) {
        super(Activity.this);
        this.required = required;
    }

    public String getValue() { return this.getText().toString(); }

    public void setKey(String key) { this.key = key; }
    public String getKey() { return this.key; }

    public void setIsQuestion(boolean value) { this.isQuestion = value; }
    public boolean getIsQuestion() { return this.isQuestion; }

    public void setQuestionKey(String value) { this.questionKey = value; }
    public String getQuestionKey() { return this.questionKey; }

    public boolean validate() {
        // Validations
    }
}

这发生在4.4及以下。在Lollipop它只是工作正常。发生在各种手机上。如果我遗漏某些内容或者扩展EditText是一个坏主意,请告诉我

1 个答案:

答案 0 :(得分:0)

看起来问题在于视图自定义,否则代码在Android 4.0.4和2.3上运行正常。

以下代码工作正常 -

        LinearLayout linearLayout = (LinearLayout) rootView.findViewById(R.id.linearLayout);
        RegistrationEditText registrationEditText = new RegistrationEditText(false, getActivity());
        registrationEditText.setBackgroundDrawable(getResources().getDrawable(R.drawable.text_box));
        linearLayout.addView(registrationEditText);

在代码中发布您的实现以了解完整的问题。

相关问题