|
|
@@ -1,59 +1,60 @@
|
|
|
package com.example.david.libretasker;
|
|
|
|
|
|
-
|
|
|
-import android.content.Intent;
|
|
|
+import android.content.Context;
|
|
|
import android.os.Bundle;
|
|
|
+import android.support.design.widget.TabLayout;
|
|
|
+import android.support.v4.app.Fragment;
|
|
|
+import android.support.v4.app.FragmentManager;
|
|
|
+import android.support.v4.app.FragmentPagerAdapter;
|
|
|
import android.support.v4.view.ViewPager;
|
|
|
import android.support.v7.app.ActionBar;
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
import android.view.Window;
|
|
|
+import android.widget.TableLayout;
|
|
|
|
|
|
|
|
|
public class MainActivity extends AppCompatActivity {
|
|
|
- ViewPager mViewPager;
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
- requestWindowFeature(Window.FEATURE_ACTION_BAR); //Call before setContentView
|
|
|
- setContentView(R.layout.activity_main);
|
|
|
-
|
|
|
- final ActionBar actionBar = getSupportActionBar();
|
|
|
- // Specify that tabs should be displayed in the action bar.
|
|
|
- actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
|
|
|
-
|
|
|
- // Create a tab listener that is called when the user changes tabs.
|
|
|
- ActionBar.TabListener tabListener = new ActionBar.TabListener() {
|
|
|
|
|
|
+ setContentView(R.layout.activity_main);
|
|
|
|
|
|
- @Override
|
|
|
- public void onTabSelected(ActionBar.Tab tab, android.support.v4.app.FragmentTransaction ft) {
|
|
|
+ ViewPager vp = (ViewPager) findViewById(R.id.pager);
|
|
|
+ vp.setAdapter(new SampleFragmentPagerAdapter(getSupportFragmentManager(),
|
|
|
+ MainActivity.this));
|
|
|
|
|
|
- }
|
|
|
+ TabLayout t = (TabLayout) findViewById(R.id.tlayout);
|
|
|
+ t.setupWithViewPager(vp);
|
|
|
|
|
|
- @Override
|
|
|
- public void onTabUnselected(ActionBar.Tab tab, android.support.v4.app.FragmentTransaction ft) {
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- @Override
|
|
|
- public void onTabReselected(ActionBar.Tab tab, android.support.v4.app.FragmentTransaction ft) {
|
|
|
+ public class SampleFragmentPagerAdapter extends FragmentPagerAdapter {
|
|
|
+ final int PAGE_COUNT = 3;
|
|
|
+ private String tabTitles[] = new String[] { "Events", "Actions", "User" };
|
|
|
+ private Context context;
|
|
|
|
|
|
- }
|
|
|
- };
|
|
|
+ public SampleFragmentPagerAdapter(FragmentManager fm, Context context) {
|
|
|
+ super(fm);
|
|
|
+ this.context = context;
|
|
|
+ }
|
|
|
|
|
|
- // Add 3 tabs, specifying the tab's text and TabListener
|
|
|
- for (int i = 0; i < 3; i++) {
|
|
|
- actionBar.addTab(
|
|
|
- actionBar.newTab()
|
|
|
- .setText("Tab " + (i + 1))
|
|
|
- .setTabListener(tabListener));
|
|
|
+ @Override
|
|
|
+ public int getCount() {
|
|
|
+ return PAGE_COUNT;
|
|
|
}
|
|
|
|
|
|
- // ViewPager and its adapters use support library
|
|
|
- // fragments, so use getSupportFragmentManager.
|
|
|
+ @Override
|
|
|
+ public Fragment getItem(int position) {
|
|
|
+ return PageFragment.newInstance(position + 1);
|
|
|
+ }
|
|
|
|
|
|
- startService( new Intent(this, MainService.class) );
|
|
|
+ @Override
|
|
|
+ public CharSequence getPageTitle(int position) {
|
|
|
+ // Generate title based on item position
|
|
|
+ return tabTitles[position];
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
}
|