【发布时间】:2017-02-24 13:03:05
【问题描述】:
我有一个framelayout 在我的Activity 中调用一次,在其他Fragment 中调用了多次(经过Activity 的同一个framelayout)。
在我的MainActivity.class 中,我需要知道我的framelayout 在哪个片段中。
例如,我需要知道framelayout 使用的是MyFragment1.class 还是MyFragment2.class。
我需要这样的东西(在这个例子中,log 必须说我“你在 MyFragment1 中”):
FrameLayout frameLayout = (FrameLayout) findViewById(R.id.framelayout);
getSupportFragmentManager().beginTransaction()
.replace(R.id.framelayout,new MyFragment1())
.commit();
if (framelayout.getname.equals("package.MyFragment1.class"))
Log.d("debug", "you are in MyFragment1");
else if (framelayout.getname.equals("package.MyFragment2.class"))
Log.d("debug", "you are in MyFragment2");
我该怎么做?
【问题讨论】:
-
查看片段管理器的标签名称
-
查看我发布的答案
-
我尝试了您的解决方案,但它不起作用(查看我的编辑)
标签: java android android-fragments android-framelayout