@Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Create database connection
    datasource = new databaseIO(this);
    datasource.open();
    allTrails = datasource.getAllTrails();

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

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Set up the ViewPager with the sections adapter.
    mViewPager = (CustomViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    // When swiping between different sections, select the corresponding tab.
    // We can also use ActionBar.Tab#select() to do this if we have a reference to the
    // Tab.
    mViewPager.setOnPageChangeListener(
        new CustomViewPager.SimpleOnPageChangeListener() {
          @Override
          public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
          }
        });

    // For each of the sections in the app, add a tab to the action bar.
    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
      // listener for when this tab is selected.
      actionBar.addTab(
          actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }
  }
Example #2
0
  private void movePage(CustomViewPager pager, int letter) {
    Log.i(
        "questionFrag",
        "count is " + pager.getAdapter().getCount() + " and current is " + pager.getCurrentItem());

    if (pager.getCurrentItem() == pager.getAdapter().getCount() - 1) {
      QuizTimeFragment.addAnswer(letter);
      Toast.makeText(getActivity(), "Test Answers Sent!", Toast.LENGTH_SHORT).show();
      helper.deleteTest(helper.getTestFromName(getArguments().getString(TESTKEY)));
      getActivity().onBackPressed();
      getActivity().onBackPressed();
      ((BrickActivity) getActivity()).resetCount();
      SmsManager sms = SmsManager.getDefault();
      sms.sendTextMessage("+2897881489", null, QuizTimeFragment.getAnswer().toString(), null, null);
      QuizTimeFragment.clearAnswers();
    } else {
      QuizTimeFragment.addAnswer(letter);
      pager.setCurrentItem(pager.getCurrentItem() + 1);
    }
  }
 @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());
 }