2015-10-12 2 views
-1

Как решить эту проблему? Я не могу решить эту проблему. Я думаю, что есть что-то не хватает в импорте. Пожалуйста, дайте мне некоторую идею.конструктор HomeActivity.SectionsPagerAdapter (FragmentManager) не определен

package me.kashyap.masking.masking; 

    import java.util.Locale; 

    import android.annotation.SuppressLint; 
    import android.app.ActionBar; 

    import android.app.FragmentTransaction; 
    import android.os.Bundle; 
    import android.support.v4.app.Fragment; 
    import android.support.v4.app.FragmentActivity; 
    import android.support.v4.app.FragmentPagerAdapter; 
    import android.support.v4.app.FragmentManager; 
    import android.support.v4.view.ViewPager; 

    @SuppressLint("NewApi") 
    public class HomeActivity extends FragmentActivity implements ActionBar.TabListener { 

     /** 
     * The {@link android.support.v4.view.PagerAdapter} that will provide 
     * fragments for each of the sections. We use a {@link FragmentPagerAdapter} 
      * derivative, which will keep every loaded fragment in memory. If this 
     * becomes too memory intensive, it may be best to switch to a 
     * {@link android.support.v13.app.FragmentStatePagerAdapter}. 
     */ 
     SectionsPagerAdapter mSectionsPagerAdapter; 

     /** 
     * The {@link ViewPager} that will host the section contents. 
     */ 
     ViewPager mViewPager; 

     @Override 
     protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.activity_home); 

      // Create the adapter that will return a fragment for each of the three 
      // primary sections of the activity. 
      mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager()); 

      // Set up the ViewPager with the sections adapter. 
      mViewPager = (ViewPager) findViewById(R.id.pager); 
      mViewPager.setAdapter(mSectionsPagerAdapter); 
      mViewPager 
       .setOnPageChangeListener(new ViewPager.OnPageChangeListener() { 
        @Override 
        public void onPageScrolled(int position, 
          float positionOffset, int positionOffsetPixels) { 

        } 

        @Override 
        public void onPageSelected(int position) { 
         getActionBar().setSelectedNavigationItem(position); 
        } 

        @Override 
        public void onPageScrollStateChanged(int state) { 

        } 
       }); 
      setTabs(); 
     } 

      private void setTabs() { 
      final ActionBar actionBar = getActionBar(); 
      actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); 

      for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { 
      // Create a tab with text corresponding to the page title defined by 
      // the adapter. Also specify this Activity object, which implements 
      // the TabListener interface, as the callback (listener) for when 
      // this tab is selected. 
      actionBar.addTab(actionBar.newTab() 
        .setText(mSectionsPagerAdapter.getPageTitle(i)) 
        .setTabListener(this)); 
      } 
     } 

     @Override 
     public void onTabSelected(ActionBar.Tab tab, 
      FragmentTransaction fragmentTransaction) { 
     // When the given tab is selected, switch to the corresponding page in 
     // the ViewPager. 
     mViewPager.setCurrentItem(tab.getPosition()); 
     } 

     @Override 
     public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) { 

     } 

     @Override 
     public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) { 

     } 

     /** 
     * A {@link FragmentPagerAdapter} that returns a fragment corresponding to 
     */ 
     public class SectionsPagerAdapter extends FragmentPagerAdapter { 

      public SectionsPagerAdapter(FragmentManager fm) { 
       super(fm); 
      } 

      public Fragment getItem(int position) { 
      // getItem is called to instantiate the fragment for the given page. 
      // Return a PlaceholderFragment (defined as a static inner class 
      // below). 
       return BaseFragment.newInstance(position); 
      } 

     public int getCount() { 
      // Show 3 total pages. 
      return 3; 
     } 

      public CharSequence getPageTitle(int position) { 
      Locale l = Locale.getDefault(); 
      switch (position) { 
      case 0: 
       return getString(R.string.title_section1).toUpperCase(l); 
      case 1: 
       return getString(R.string.title_section2).toUpperCase(l); 
      case 2: 
       return getString(R.string.title_section3).toUpperCase(l); 
       } 
       return null; 
      } 
     } 
    } 
+0

'getSupportFragmentManager()' мой друг – Neil

+0

где я реализовать эту линию –

+0

'mSectionsPagerAdapter = новый SectionsPagerAdapter (getSupportFragmentManager());' – Neil

ответ

0

Передайте Context внутри

mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager()); 

вместо getFragmentManager()

+0

Я делаю то же самое, но ошибка остается постоянной –

+0

Проверьте, были ли вы импортированы все необходимые библиотеки поддержки – Jas

+0

Я разрешаю ошибку, добавляя 'getSupportFragmentManager()' –

Смежные вопросы