I have an activity extends from FragmentActivity
, and I have four TABS of Fragments
, I have AsyncTask
in main FragmentActivity
to get load data from a server, so, I want to update each Fragment data when complete the AsyncTask function on parent FragmentActivity, since I'm using android.support.v4.view.ViewPager
all the Fragment's UI loading when starts the Activity with blank data, so, I want to update the each fragment fields (TextView) with the data getting from AsyncTask, How I can update. Appreciate your help. The below code using for get Fragment
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
Fragment fragmenthome = new HomeFragment();
return fragmenthome;
case 1:
Fragment fragmentdiagnosis = new DiagnosisFragment();
return fragmentdiagnosis;
case 2:
Fragment fragmentcareplan = new CareplanFragment();
return fragmentcareplan;
case 3:
Fragment fragmentnote = new NoteFragment();
return fragmentnote;
case 4:
Fragment fragmenttask = new TaskFragment();
return fragmenttask;
}
return null;
}
And here is a sample Fragment
public static class DummySectionFragment extends Fragment {
/**
* The fragment argument representing the section number for this
* fragment.
*/
public static final String ARG_SECTION_NUMBER = "section_number";
public DummySectionFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main_dummy,container, false);
TextView dummyTextView = (TextView) rootView.findViewById(R.id.section_label);
dummyTextView.setText("Comming Soon...");
return rootView;
}
}
here is the main Activity
public class PatientActivity extends FragmentActivity implements ActionBar.TabListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_patient);
// AsyncTask function calling
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…