0

Jake Wharton의 ViewPagerIndicator 라이브러리를 사용하고 있고 화면을 회전 할 때 아래에 표시된 FragmentActivity에서 onCreate 메서드가 호출되었지만 활동이 비어 있고 표시기 ('탭 1'및 '탭' 2 ').화면 회전 후 FragmentActivity 복구

public class MainActivity extends FragmentActivity { 

    private static final String[] CONTENT = new String[] { "Tab 1", "Tab 2", }; 

    ProgressDialog progress; 

    FragmentPagerAdapter adapter; 
    ViewPager pager; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 

     super.onCreate(savedInstanceState); 

     progress = ProgressDialog.show(this, "Loading", "Loading data..."); 

     new getData().execute(); 

    } 

    @Override 
    protected void onSaveInstanceState(Bundle outState) { 

     super.onSaveInstanceState(outState); 

    } 

    class FragPagerAdapter extends FragmentPagerAdapter { 
     public FragPagerAdapter(FragmentManager fm) { 
      super(fm); 
     } 

     @Override 
     public Fragment getItem(int position) { 
      if(position == 0){ 
       return FragmentTabOne.newInstance(); 
      }else if(position == 1){ 
       return FragmentTabTwo.newInstance(); 
      } 
      return null; 
     } 

     @Override 
     public CharSequence getPageTitle(int position) { 
      return CONTENT[position % CONTENT.length].toUpperCase(); 
     } 

     @Override 
     public int getCount() { 
      return CONTENT.length; 
     } 

    } 

    private class getData extends AsyncTask<Void, Void, Boolean> { 

     @Override 
     protected Boolean doInBackground(Void... params) { 

      //getting data from server 

      return true; 
     } 

     protected void onPostExecute(final Boolean success) { 

       setContentView(R.layout.main_activity); //indicator + viewpager 

       adapter = new FragPagerAdapter(getSupportFragmentManager()); 

       pager = (ViewPager)findViewById(R.id.pager); 

       pager.setAdapter(adapter); 

       TabPageIndicator indicator = (TabPageIndicator)findViewById(R.id.indicator); 
       indicator.setViewPager(pager); 

       progress.dismiss(); 

      } 
     } 

    } 
} 

액티비티 및 해당 단편을 올바르게 표시하려면 어떻게해야합니까 (아마 onSaveInstanceState 메서드에서)? 감사합니다

답변

1

조각에서 'onCreateView()setRetainInstance(true)

에 전화를 걸어보세요.