在运行时在 DialogFragment 中设置可见性视图
Set visibility view in DialogFragment at runtime
我正在尝试在运行时更新 DialogFragment 显示,根据某些条件将视图的可见性设置为 VISIBLE 或 GONE。
基本上,我在 DialogFragment 中扩充我的布局,在我执行一些后台请求时显示进度条,并根据我的请求结果更新 DialogFragment 布局。
有时它有效,有时它不会相应地更新我的 UI,即使日志显示该方法已被调用并且该线程是主线程。
知道为什么吗?
在 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);
}
}
在Activity
@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 中执行另一个 UseCase。
我将我的代码拆分到两个不同的对话框中以使其更简单,并且只有一个用例更新 UI,没有更多问题。
我正在尝试在运行时更新 DialogFragment 显示,根据某些条件将视图的可见性设置为 VISIBLE 或 GONE。
基本上,我在 DialogFragment 中扩充我的布局,在我执行一些后台请求时显示进度条,并根据我的请求结果更新 DialogFragment 布局。
有时它有效,有时它不会相应地更新我的 UI,即使日志显示该方法已被调用并且该线程是主线程。 知道为什么吗?
在 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);
}
}
在Activity
@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 中执行另一个 UseCase。
我将我的代码拆分到两个不同的对话框中以使其更简单,并且只有一个用例更新 UI,没有更多问题。