Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have an activity extends from FragmentActivity, and I have four TABS of Fragments, I have AsyncTask in main FragmentActivityto 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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
451 views
Welcome To Ask or Share your Answers For Others

1 Answer

Create method in fragment which updates the text in text view,access fragment method from the fragment activity.

DemoFragment demo_frag = (DemoFragment)getSupportFragmentManager().findFragmentByTag("Demo_Fragment");
 demo_frag.updateTextView();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...