I need help with reloading a Fragment that is part of a ViewPager. Here is my current setup: ReportActivity extends FragmentActivity and uses ViewPager to host 4 Tabs TAB 1 to 4. Each Tab is a Fragment with seperate layout.
ViewPager uses TabsPagerAdapter to switch between the tabs and this works as expected.
TAB1Fragment displays a graph using a static dataset. Now I have added a spinner to dynamically change the dataset and I am looking for ways to reload the Fragment so it can re-display the graph with the correct dataset. The following ints correspond to the values of the Spinner.
static final int REPORT_PERIOD_DAY = 0;
static final int REPORT_PERIOD_WEEK = 1;
static final int REPORT_PERIOD_MONTH = 2;
static final int REPORT_PERIOD_YEAR = 3;
I have a method that correctly calculates the correct data based on the the int passed in, what I am struggling with is how to create an Intent or any other method that will recreate TAB1Fragment and passes it an int parameter.
Here is where I want to re-create the Fragment
mReportPeriodSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switch (position){
case 0:
//How can I re-load the Fragment here?
reloadFragment(REPORT_PERIOD_DAY);
break;
case 1:
reloadFragment(REPORT_PERIOD_WEEK);
break;
case 2:
reloadFragment(REPORT_PERIOD_MONTH);
break;
case 3:
reloadFragment(REPORT_PERIOD_YEAR);
break;
}
}
Please can you give me an idea of how to write the code that goes into the method reloadFragment(Int period)