2014-09-02 4 views
-1

내가 활동이 FragmentActivity에서 확장 있고, 내가 Fragments의 네 개의 탭이있을 때 FragmentActivity에서 조각 텍스트 뷰를 업데이트하는 방법, 내가 업데이트 할, 서버에서 부하 데이터를 가져 오기 위해 주요 FragmentActivity에서 AsyncTask, 그래서 각 조각 데이터는 부모 데이터에서 AsyncTask 함수를 완료 할 때 android.support.v4.view.ViewPager 빈 데이터로 작업을 시작할 때 모든 조각의 UI 로딩을 사용하므로 AsyncTask에서 가져 오는 데이터로 각 조각 필드 (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가 {

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_patient); 
    // AsyncTask function calling 

ActionBar.TabListener를 구현 확장의 주요 활동을하는 샘플 조각입니다 }

+1

일부 코드를 표시하십시오. – Piyush

+0

코드는 SectionsPagerAdapter mSectionsPagerAdapter를 사용하여 TABS of Fragments의 기본 활동입니다. –

+0

onPost가 실행되면 조건을 사용하여 onResume()을 처리하고 플래그를 true로 표시하고 여기에 업데이트 코드를 입력하십시오. –

답변

0

fra의 메소드 만들기 text 뷰에서 텍스트를 갱신하는 gment, fragment 활동에서 fragment 메소드를 액세스하십시오.

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

이 "Demo_Fragment"는 무엇이며 어디에서 찾을 수 있습니까? –

+0

"Demo_Fragment"는 조각을 추가/대체 할 때 제공하는 태그입니다. 이 같은 단편 호출있어 – Dory

+0

, \t \t @Override \t \t 공개 조각의 getItem (INT 위치) { \t \t \t 스위치 (위치) { \t \t \t 경우 0 \t \t \t \t 단편 fragmenthome = 새로운 HomeFragment(); \t \t \t \t \t \t \t \t return fragmenthome; \t \t \t \t \t \t \t 경우 1 : –