Jamie Smith Jamie Smith - 2 years ago 67
Java Question

String doesn't update when passed to different Fragment?

I'm trying to send two strings from Fragment A to Fragment B. Currently, i've implemented an

listener like this...

Fragment A Method:

String arrayTitle1 = arrayList.get(Index).get("ArrayTitle1");
String arrayTitle2 = arrayList.get(Index).get("ArrayTitle2");

((TextFooterListener) getActivity()).onTextFooterListener(arrayTitle1, arrayTitle2);

I pass these strings to the Activity which sends them to Fragment B like this...


public void onTextFooterListener(String arrayTitle1, String arrayTitle2) {

FragmentB.arrayTitle1 = arrayTitle1;
FragmentB.arrayTitle2 = arrayTitle2;


Fragment B:

They are then received and stored in Fragment B as public strings.

public String arrayTitle1;
public String arrayTitle2;

And in the
of Fragment B, i try to assign these strings.


But unfortunately, whenever Fragment A's method gets called, the
doesn't seem to update the strings.

Any suggestions?

Answer Source

You change the values in Fragment B but never actually reassign the new values into the TextViews.


public void onTextFooterListener(String arrayTitle1, String arrayTitle2) {
    FragmentB.setTitles(arrayTitle1, arrayTitle2);

And in Fragment B :

public void setTitles(String title1, String title2) {
    arrayTitle1 = title1;
    arrayTitle2 = title2;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download