Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.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 如何在对话框关闭操作时以编程方式更新自定义对话框首选项布局?_Android - Fatal编程技术网

Android 如何在对话框关闭操作时以编程方式更新自定义对话框首选项布局?

Android 如何在对话框关闭操作时以编程方式更新自定义对话框首选项布局?,android,Android,试图在自定义的对话框首选项布局上添加文本视图,我试图在对话框框架关闭且新值保存到首选项时更改此文本视图 为此,我尝试保存首选项的根视图,覆盖onBindView方法: @Override protected void onBindView(View view) { super.onBindView(view); // saving reference to view of preference parentView = view; } 然后,使用它在notifyChan

试图在自定义的
对话框首选项
布局上添加
文本视图
,我试图在对话框框架关闭且新值保存到首选项时更改此
文本视图

为此,我尝试保存首选项的根视图,覆盖
onBindView
方法:

@Override
protected void onBindView(View view) {
    super.onBindView(view);
    // saving reference to view of preference
    parentView = view;
}
然后,使用它在
notifyChanged
上更新我的
TextView
实例:

@Override
protected void notifyChanged() {
    super.notifyChanged();
    if (parentView != null) {
        // finding target element
        View tagView = parentView.findViewWithTag("price_value");
        // setting new value to custom TextView
        ((TextView) tagView).setText(getText());
    }

}
然而,文本不会更新,直到我将片段切换到另一个片段,然后从活动切换回首选项片段

更改片段的代码:

private void _loadMainFragment(Fragment mainFragment) {
    FragmentManager mFragmentManager = getFragmentManager();
    FragmentTransaction mFragmentTransaction =
            mFragmentManager.beginTransaction();
    mFragmentTransaction.replace(R.id.main_container, mainFragment);
    mFragmentTransaction.addToBackStack(null);
    mFragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    mFragmentTransaction.commit();
}

有人能给我一个提示,为什么TextView没有第一次更新,或者在哪里进行挖掘吗?

需要调用:

tagView.invalidate();
tagView.requestLayout()

在应该更新的视图上