我有一个framelayout
在我的Activity
调用一次,并在其他Fragment
(通过Activity
相同的framelayout
)调用各种时间。获取片段名称或ID
在我的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");
但我不知道我怎么能做到这一点。
查找到的标记名称的片段经理 –
检查答案我张贴 –
我试试你的解决方案,但它不工作(看我的编辑) –