0
我知道在xml中生成片段的标识的方法,但是如何在java类中执行此操作? 由于它喜欢public class MenuFragment extends Fragment{}
。而我想findFragmentByTag或findFragmentById使用它们后来如何在Android类中为片段生成标识或标签
我知道在xml中生成片段的标识的方法,但是如何在java类中执行此操作? 由于它喜欢public class MenuFragment extends Fragment{}
。而我想findFragmentByTag或findFragmentById使用它们后来如何在Android类中为片段生成标识或标签
// Create a constant in class MenuFragment
public final static String TAG = "MenuFragmentTag";
以后它可以用于创建使用findFragmentByTag片段:
getFragmentManager().findFragmentByTag(MenuFragment.TAG);
谢谢you.But如果有很多碎片,代码会很难看。那么有没有更好的方法来解决这个问题? – Marshall
嘿,这是我知道什么时候片段没有在XML中定义的唯一途径。 – Permita