0

I need to locate the fragment currently being shown by a FragmentActivity.

Alternatively, I need to find the Fragment that implements a given Interface.

    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?

How do I accomplish this ?

CodePrimate
  • 6,646
  • 13
  • 48
  • 86

2 Answers2

0

You can call findFragmentById() on FragmentManager and determine which fragment is displayed.

Akram Fares
  • 1,653
  • 2
  • 17
  • 32
0

You have to use the fragment manager.

There are 2 Methods:

findFragmentByTag and findFragmentById

If you pushed the fragment into a layout you can reference it by the layout id.

The Tag can be null or set by the programmer before.

You also can iterate through the stack of the fragment manager.

to get the SupportFragmentManager, write inside a FragmentActivity:

getSupportFragmentManager()
redestructa
  • 1,182
  • 1
  • 11
  • 11