0

I'm a beginner in android development. I have a Fragment (FragA) in which I have a button that does a calculation and set the value to a variable (x) and pass this value to another fragment (FragB). Every time I press the button in FragA the value of "x" is passed to FragB.

Now, what I want is to do an action in FragB (refresh the view of a graph) each time the value of "x" is changed. If you need more information feel free to ask.

Thanks

Onyx
  • 13
  • 1
  • 4
  • Sounds like you already have a mechanism to pass the value between fragments, so what is the remaining problem? – Markus Kauppinen Nov 19 '16 at 18:11
  • @MarkusKauppinen I need a way to fire the refresh of my graph, because right now I have to close the activity and re-open it if I want my graph to show the new value. – Onyx Nov 19 '16 at 19:37
  • Or is it possible to use the onClick() in FragA to directly tel FragB to fire a sequence of actions? – Onyx Nov 19 '16 at 20:33
  • you can use `interface` for that. Follow http://stackoverflow.com/a/13701071/3758972 – Nitesh Verma Nov 20 '16 at 03:35

1 Answers1

0

I found a way to make a RealTime chart here. The important part is:

public class BH06_Graph_Frag extends Fragment{
private Runnable mTimer;
//i.e private LineGraphSeries<DataPoint> mSeries;

...

@Override
public void onResume() {
    super.onResume();

    mTimer = new Runnable() {
        @Override
        public void run() {

              //reception of value "x"
              //do something
              // i.e mSeries.resetData(new DataPoint[] {
              //    new DataPoint(6, x) });
              //    

            mHandler.postDelayed(this, 300);
        }
    };
    mHandler.postDelayed(mTimer, 300);
}
Onyx
  • 13
  • 1
  • 4