我有一個活動從FragmentActivity
延伸,我有Fragments
四個選項卡,我在主FragmentActivity
AsyncTask
從服務器獲取負荷數據,所以,我想更新每個Fragment數據在完成父FragmentActivity上的AsyncTask函數時,因爲我使用的是android.support.v4.view.ViewPager
所有Fragment的UI加載時用空白數據啓動Activity,所以,我想用從AsyncTask獲取的數據更新每個片段字段(TextView) ,我如何更新。感謝你的幫助。使用中獲取片段如何從FragmentActivity更新分段的TextView時光潔度的AsyncTask
@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;
}
在這裏,下面的代碼是一個示例片段
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;
}
}
這裏是主要的活動 公共類PatientActivity擴展FragmentActivity實現ActionBar.TabListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_patient);
// AsyncTask function calling
}
顯示一些代碼。 – Piyush 2014-09-02 09:13:51
該代碼基本活動與碎片的TABS,使用SectionsPagerAdapter mSectionsPagerAdapter; – 2014-09-02 09:15:39
你可以在onResume()中使用條件處理,如果onPost得到執行,然後將該標誌標記爲true,並在那裏執行更新代碼 – 2014-09-02 09:17:53