Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 覆盖edtitext';s getText()方法导致堆栈溢出,为什么?_Android_Android Textinputlayout - Fatal编程技术网

Android 覆盖edtitext';s getText()方法导致堆栈溢出,为什么?

Android 覆盖edtitext';s getText()方法导致堆栈溢出,为什么?,android,android-textinputlayout,Android,Android Textinputlayout,我正在对TextInputItemText进行子类化,以便可以向password editText字段添加字符串。下面是子类: public class CustomInputEditTextWithPrefix extends TextInputEditText { public CustomInputEditTextWithPrefix(Context context) { super(context); } public CustomInputEditTextWithPref

我正在对TextInputItemText进行子类化,以便可以向password editText字段添加字符串。下面是子类:

public class CustomInputEditTextWithPrefix extends TextInputEditText {


public CustomInputEditTextWithPrefix(Context context) {
    super(context);
}

public CustomInputEditTextWithPrefix(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public CustomInputEditTextWithPrefix(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
}

@Override
public Editable getText() {
    Editable s = (Editable) super.getText(); //why is this causing infinite stackoverflow ?
    if(s!=null && s.length()>0) {
      //salt the password
        Editable pwSalt = new SpannableStringBuilder("my secret string");
        s= pwSalt.append(s);
    }
     return s;
}
}

xml中的实现是:

<com.myapp.ui.auth.ui.customviews.CustomInputEditTextWithPrefix
           android:id="@+id/password"
           android:inputType="textPassword" />


我的问题是,当我执行代码时,getText()override方法会不断被调用。我取出了inputType,但直到stackoverflow它才被调用。我的想法是在TextInputItemText中每个字符串的前面附加一个秘密哈希。我做错了什么?

如果您跳过指定一个新值
s
,一切都会好起来

   @Override
    public Editable getText() {
        Editable s = (Editable) super.getText();
        if(s!=null && s.length()>0) {
            //salt the password
            return new SpannableStringBuilder("my secret string").append(s.toString());
        }
        return s;
    }