Viewpager第一页选择了意图错误

时间:2013-07-08 08:47:49

标签: android android-viewpager

ViewPager Main.class第一页单击“运行” Page 2 main2.class单击“运行” 我使用了Intent,但失败了 我该怎么办

public class MainActivity extends FragmentActivity {

SectionsPagerAdapter mSectionsPagerAdapter;
ViewPager mViewPager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.merkez);
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());


    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);  basla();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}
public class SectionsPagerAdapter extends FragmentPagerAdapter {

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

    }

    @Override
    public Fragment getItem(int position) {
        Fragment fragment = new DummySectionFragment();

        return fragment;

    }
    @Override
    public int getCount() {
        return 3;
    }



    @Override
    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;
    }
}

public static class DummySectionFragment extends 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.main,container, false);

            return rootView;
    }
}
private void basla()
{
    mViewPager.setOnPageChangeListener(new OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            // TODO Auto-generated method stub

            switch(position){  

            case 0:    
                Intent Main=new Intent(MainActivity.this,Main.class);
                    startActivity(Main);
                break;  

            case 1:    
                Intent Main2=new Intent(MainActivity.this,Main.class);
                startActivity(Main2);
                break;  

            case 2:  

                Intent Main3=new Intent(MainActivity.this,Main.class);
                startActivity(Main3);

                break;  
            }  
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onPageScrollStateChanged(int arg0) {
            // TODO Auto-generated method stub

        }
    });

}
}

(注意:main.class扩展Activity

英语是一个简单的级别

我转向谷歌翻译的帮助

0 个答案:

没有答案