Android:Fragment!isDetached()和iwego()有什么区别? [英] Android: what is the difference between Fragment !isDetached() and isAdded()?

查看:67
本文介绍了Android:Fragment!isDetached()和iwego()有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Fragment中,一旦要加载一些数据,我想做一个Toast,像这样:

In my Fragment, I want to make a Toast once some data is loaded, like this:

Toast.makeText(getActivity(), R.string.toast_loading_done,
        Toast.LENGTH_SHORT).show();

仅当Fragment仍附加到Activity时才有意义,即Fragment是可见的,并且getActivity()不会返回null.

This only makes sense if the Fragment is still attached to the Activity, i.e. the Fragment is visible and getActivity() will not return null.

我可以使用!isDetached() i☎联系人()进行检查,对吗?在这里,我想知道两种方法之间的区别是什么,我最好使用哪种方法?

I could check that with !isDetached() or with isAdded(), right? Here I am wondering what the difference between the two methods is and which one I should preferably use?

推荐答案

Fragment 可以附加到 Activity ,而无需添加到其视图层次结构中.

A Fragment can be attached to an Activity without being added to it's view hierarchy.

如果 Fragment 被分离,则其状态得以维护并且可以重新添加.

If a Fragment is detached, it's state is maintained and can be re-added.

这篇关于Android:Fragment!isDetached()和iwego()有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆