S
S
SimpleName2019-01-27 20:24:37
css
SimpleName, 2019-01-27 20:24:37

How can one implement passing the FirebaseDatabase.getInstance().getReference method from one fragment to another?

There are two buttons in the fragment. Each of them now leads to a fragment with a RecyclerView, but we need to make sure that completely different data is loaded into it depending on the button that was clicked. Data is loaded from Firebase using the getReference method. It turns out that when you click on the first button, it should work

mRef = FirebaseDatabase.getInstance().getReference("DataOne");
, and when passing through the second
mRef = FirebaseDatabase.getInstance().getReference("DataTwo");

Can this be done using only one fragment? And how? Or do I need to create a separate fragment for each button?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
display: block, 2016-06-06
@mih_max

Anchor link should look like this:
radioroomy.com/pyat-knig-o-lyubvi#two
Instead of:
radioroomy.com/#two
In modx, it is convenient to form a link in this way
<a href="#two">...</a>

I
ivanessence, 2019-01-28
@SimpleName

You can pass the required string in the following way:
- Create a static method in the fragment class to which we will pass the string

public static FragmentSimpleName newInstance(String line) {
        FragmentSimpleName fragment = new FragmentSimpleName ();
        Bundle args = new Bundle();
        args.putString("line", line);
        fragment.setArguments(args);
        return fragment;
    }

- and then in the onCreate method we get the string that was passed
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        String line = getArguments() != null ? getArguments().getString("line") :  "DataOne";
    }

- Create a fragment in the following way
And then, depending on the received string, you set up your fragment. More details here

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question