Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如果我想在页面中加上网络请求时等待的弹窗,是否有较好的办法 #19

Open
Destroyer716 opened this issue Jun 27, 2019 · 2 comments

Comments

@Destroyer716
Copy link

比如在网络请求开始前显示loading 弹窗,网络请求结束时销毁弹窗,ViewModel里面调用Model层获取数据,那么在调用Model层前显示loading,请求结束时销毁loading,而ViewModel不建议应用View层,我该如何通知View层去显示或者销毁loading弹窗呢,暂时我想到的办法是另外每个页面都需要单独定义一个LiveData去设置显示还是销毁,然后View层观察他的值的变化。

想问下有没有更好的办法。

@xchengDroid
Copy link

在ViewModel 里面定义一个public 的 loadingLiveData.,开始和结束发送数据,然后在View层去添加observer

@xchengDroid
Copy link

如 LiveData loadingLiveData=new LiveData<>();
loadingLiveData.setValue(true|false)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants