我有一個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");
但我不知道我怎麼能做到這一點。
查找到的標記名稱的片段經理 –
檢查答案我張貼 –
我試試你的解決方案,但它不工作(看我的編輯) –