繁体   English   中英

在运行时在DialogFragment中设置可见性视图

[英]Set visibility view in DialogFragment at runtime

我试图在运行时更新DialogFragment显示,根据某些条件将视图的可见性设置为VISIBLE或GONE。

基本上,我在DialogFragment中增加布局,在执行一些后台请求时显示进度条,并根据请求的结果更新DialogFragment布局。

有时它可以工作,有时它不会相应地更新我的UI,即使日志显示该方法已被调用并且该线程是Main线程也是如此。 知道为什么吗?

在DialogFragment中

@Override
public void showData(List<MyDataViewModel> data) {
    Timber.d("Fragment Show data " + (Looper.myLooper() == Looper.getMainLooper()));
    Timber.d("Fragment Show data " + this);
    Timber.d("Fragment Show data " + data.size());

    if (mConnectedContainer.getVisibility() != View.VISIBLE) {
        mConnectedContainer.setVisibility(View.VISIBLE);
    }
}

活动中

@Override
public void showDialog() {
    // DialogFragment.show() will take care of adding the fragment
    // in a transaction.  We also want to remove any currently showing
    // dialog, so make our own transaction and take care of that here.
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    Fragment prev = getSupportFragmentManager().findFragmentByTag("dialog");
    if (prev != null) {
        ft.remove(prev);
    }
    ft.addToBackStack(null);

    // Create and show the dialog.
    DialogFragment newFragment = MyDialogFragment.newInstance();
    newFragment.show(ft, "dialog");
}

也尝试过这种方式

@Override
public void showDialog() {
    // Create and show the dialog.
    DialogFragment newFragment = MyDialogFragment.newInstance();
    newFragment.show(getSupportFragmentManager(), "dialog");
}

经过调查后,该问题与我对RxJava的使用有关。 我正在执行第一个UseCase,然后在onNext中执行另一个。

我将代码分成两个不同的对话框以使其更简单,并且只有一个用例可以更新UI,没有其他问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM