Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/209.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.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-更改EditTextPreference';以编程方式创建对话框_Android_Android Preferences_Android Edittext_Android Dialog - Fatal编程技术网

Android-更改EditTextPreference';以编程方式创建对话框

Android-更改EditTextPreference';以编程方式创建对话框,android,android-preferences,android-edittext,android-dialog,Android,Android Preferences,Android Edittext,Android Dialog,我正在尝试更改“EditTextPreference”中的对话框的正按钮文本。我尝试了以下方法,但没有成功: // The reference to the preference in the view heirarchy mUrlPreference = (EditTextPreference) getPreferenceScreen().findPreference(pref); // Add a textwatcher mUrlPreferen

我正在尝试更改“EditTextPreference”中的
对话框
正按钮文本
。我尝试了以下方法,但没有成功:

    // The reference to the preference in the view heirarchy
    mUrlPreference = (EditTextPreference) getPreferenceScreen().findPreference(pref);       
    // Add a textwatcher
    mUrlPreference.getEditText().addTextChangedListener(prefWatcher);
prefWatcher
如下所示:

private TextWatcher prefWatcher = new TextWatcher() {

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count,
            int after) {

    }

    @Override
    public void afterTextChanged(Editable s) {
        Log.i(TAG_LOG, "Updating the positive button text");
        mUrlPreference.setPositiveButtonText("Download");
    }
};

当我更改EditText中的文本时,会打印日志,但肯定按钮文本不会更改。这里有我遗漏的东西吗?我最初的想法是,我必须刷新对话框的视图层次结构,但我在API中没有看到任何方法可以做到这一点。关于我这里缺少的内容,有什么想法吗?

根据的文档,更新后的文本将显示在后续对话框中。因此,要实际影响按钮,请执行以下操作:

@Override
public void afterTextChanged(Editable s) {
    mUrlPreference.setPositiveButtonText("Download");

    Button button = (Button) mUrlPreference.getDialog().findViewById(android.R.id.button1);
    button.setText("Download");
    button.invalidate(); // if necessary
}

谢谢但是你是如何得到阳性按钮的id的?@500865 button_positive最初被称为。提到了id。