Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何通过编程查找FragmentActivity当前显示的片段?_Android_Android Fragments - Fatal编程技术网

Android 如何通过编程查找FragmentActivity当前显示的片段?

Android 如何通过编程查找FragmentActivity当前显示的片段?,android,android-fragments,Android,Android Fragments,我需要找到FragmentActivity当前显示的片段 或者,我需要找到实现给定接口的片段 public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (EditorInfo.IME_ACTION_DONE == actionId) { // Return input text to fragment AdjustPricesDialogListener

我需要找到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?

如何完成此操作?

您可以在FragmentManager上调用findFragmentById(),并确定显示哪个片段。

您必须使用片段管理器

有两种方法:

findFragmentByTag和findFragmentById

如果将片段推入布局,则可以通过布局id引用它

标签可以是空的,也可以由程序员设置

您还可以遍历片段管理器的堆栈

要获取SupportFragmentManager,请在FragmentActivity中写入:

getSupportFragmentManager()
类似问题: