0

I have a fragment where I use a button and in the onCreateView() call the button.

I declare these attributes in the Fragment:

Button button;
Carrier carrier;

In the onCreateView() method I assign values to them:

button =v.findViewById(R.id.button);
carrier = getCarrier();

I use these in the onStart() method:

button.setOnClickListener(this);
button.setBackgroundColor(ContextCompat.getColor(getContext(),carrier.getColourResource()));

When I minimize and return the buttonValue does not become null, but the carrier value becomes null.

Why does it happen like this? Should it not be uniform for both the objects?

The carrier class:

public class Carrier {
private Integer colourResource = 0;

public Carrier(Integer colourResource) {
        setColourResource(colourResource);     
    }

public Integer getColourResource() {
        return colourResource;
    }

 public void setColourResource(int resource) {
        colourResource = new Integer(resource);
    }
}

This fragment which I am loading is based on a Parent fragment

It is like public class ThisFragment extends ParentFragment {}

The parent fragment:

public class ParentFragment() extends Fragment{
private Carrier carrier;

public void setCarrier(int color) {
        carrier = new Carrier(new Integer(color));
    }

public Carrier getCarrier() {
        return carrier;

    }
}
Dinesh
  • 889
  • 14
  • 34

0 Answers0