2013-05-03 54 views
0

我需要找到當前由FragmentActivity顯示的片段。如何以編程方式查找當前由FragmentActivity顯示的片段?

或者,我需要找到實現給定接口的片段。

public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
    if (EditorInfo.IME_ACTION_DONE == actionId) { 
     // Return input text to fragment 
     AdjustPricesDialogListener fragment = (AdjustPricesDialogListener) ??? // how do I find this fragment? 

我該如何做到這一點?

+0

Simmilar問題:http://stackoverflow.com/questions/9294603/get-currently-displayed-fragment – Apfelsaft 2013-05-03 12:02:05

回答

0

您必須使用片段管理器。

有兩種方法:

findFragmentByTag和findFragmentById

如果你推片段插入您可以通過佈局ID號和它的佈局。

標記可以爲空或由程序員設置之前。

您也可以迭代片段管理器的堆棧。

得到SupportFragmentManager,一個FragmentActivity裏面寫:

getSupportFragmentManager() 
0

您可以在FragmentManager上調用findFragmentById()並確定顯示哪個片段。

相關問題