|
| 1 | +package com.turingtechnologies.materialscrollbardemo.Activities; |
| 2 | + |
| 3 | +import android.content.Intent; |
| 4 | +import android.os.Bundle; |
| 5 | +import android.support.v4.app.Fragment; |
| 6 | +import android.support.v4.app.FragmentManager; |
| 7 | +import android.support.v4.app.FragmentStatePagerAdapter; |
| 8 | +import android.support.v4.view.ViewPager; |
| 9 | +import android.support.v7.app.AppCompatActivity; |
| 10 | +import android.view.Menu; |
| 11 | +import android.view.MenuItem; |
| 12 | + |
| 13 | +import com.turingtechnologies.materialscrollbardemo.Fragments.FirstLetterFragment; |
| 14 | +import com.turingtechnologies.materialscrollbardemo.R; |
| 15 | + |
| 16 | +public class MultiFragmentActivity extends AppCompatActivity { |
| 17 | + |
| 18 | + @Override |
| 19 | + protected void onCreate(Bundle savedInstanceState) { |
| 20 | + super.onCreate(savedInstanceState); |
| 21 | + setContentView(R.layout.activity_multi_frag); |
| 22 | + |
| 23 | + ViewPager pager = findViewById(R.id.fragmentViewPager); |
| 24 | + pager.setAdapter(new ScreenSlidePagerAdapter(getSupportFragmentManager())); |
| 25 | + } |
| 26 | + |
| 27 | + @Override |
| 28 | + public boolean onCreateOptionsMenu(Menu menu) { |
| 29 | + // Inflate the menu; this adds items to the action bar if it is present. |
| 30 | + getMenuInflater().inflate(R.menu.menu_frags, menu); |
| 31 | + return true; |
| 32 | + } |
| 33 | + |
| 34 | + @Override |
| 35 | + public boolean onOptionsItemSelected(MenuItem item) { |
| 36 | + // Handle action bar item clicks here. The action bar will |
| 37 | + // automatically handle clicks on the Home/Up button, so long |
| 38 | + // as you specify a parent activity in AndroidManifest.xml. |
| 39 | + int id = item.getItemId(); |
| 40 | + |
| 41 | + //noinspection SimplifiableIfStatement |
| 42 | + if(id == R.id.action_toAlpha) { |
| 43 | + Intent i = new Intent(this, MainActivity.class); |
| 44 | + i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); |
| 45 | + startActivity(i); |
| 46 | + return true; |
| 47 | + } |
| 48 | + |
| 49 | + return super.onOptionsItemSelected(item); |
| 50 | + } |
| 51 | + |
| 52 | + |
| 53 | + private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { |
| 54 | + public ScreenSlidePagerAdapter(FragmentManager fm) { |
| 55 | + super(fm); |
| 56 | + } |
| 57 | + |
| 58 | + @Override |
| 59 | + public Fragment getItem(int position) { |
| 60 | + return new FirstLetterFragment(); |
| 61 | + } |
| 62 | + |
| 63 | + @Override |
| 64 | + public int getCount() { |
| 65 | + return 2; |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | +} |
0 commit comments