title: Intent From fragment to Second Tab
body: <p>I have tab layout in android with viewpager in my Main Activity. I have three Tab with three Fragment. And in first fragment i have button i want to intent on second tab from that button on click. how to intent please help me.
  Here is my Code</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      //Declaring All The Variables Needed
  
      private Toolbar toolbar;
      private TabLayout tabLayout;
      private ViewPager viewPager;
      private ViewPagerAdapter viewPagerAdapter;
  
      public static final String PREFS_NAME = "MyPrefsFile";
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
  
          SharedPreferences settings = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
          String name = settings.getString("first", "str1");
  
          //str1 = intent.getStringExtra("first");
          Toast.makeText(MainActivity.this, "" + name, Toast.LENGTH_SHORT).show();
  
  
          toolbar = (Toolbar) findViewById(R.id.toolbar);
          tabLayout = (TabLayout) findViewById(R.id.tabs);
          viewPager = (ViewPager) findViewById(R.id.viewpager);
          FragmentManager manager = getSupportFragmentManager();
          ViewPagerAdapter adapter = new ViewPagerAdapter(manager);
          viewPager.setAdapter(adapter);
          tabLayout.setupWithViewPager(viewPager);
          viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
          tabLayout.setTabsFromPagerAdapter(adapter);
  
          tabLayout.setTabTextColors(ContextCompat.getColorStateList(this, R.drawable.tab_selector));
          viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
          setSupportActionBar(toolbar);
          final FloatingActionMenu floatingActionsMenu=(FloatingActionMenu) findViewById(R.id.material_design_android_floating_action_menu);
          final FloatingActionButton floatingActionButton1=(FloatingActionButton)findViewById(R.id.material_design_floating_action_menu_item1);
          floatingActionButton1.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Toast.makeText(MainActivity.this, "Table", Toast.LENGTH_SHORT).show();
                  viewPager.setCurrentItem(0);
                floatingActionsMenu.close(true);
              }
          });
  
          FloatingActionButton floatingActionButton2=(FloatingActionButton)findViewById(R.id.material_design_floating_action_menu_item2);
          floatingActionButton2.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Toast.makeText(MainActivity.this, "Order", Toast.LENGTH_SHORT).show();
                  viewPager.setCurrentItem(1);
                  floatingActionsMenu.close(true);
              }
          });
          FloatingActionButton floatingActionButton3=(FloatingActionButton)findViewById(R.id.material_design_floating_action_menu_item3);
          floatingActionButton3.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Toast.makeText(MainActivity.this, "Logout", Toast.LENGTH_SHORT).show();
              }
          });
      }
  
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // Handle action bar item clicks here. The action bar will
          // automatically handle clicks on the Home/Up button, so long
          // as you specify a parent activity in AndroidManifest.xml.
          int id = item.getItemId();
  
          //noinspection SimplifiableIfStatement
          if (id == R.id.action_settings) {
              Intent tologin=new Intent(MainActivity.this,LoginPage.class);
              startActivity(tologin);
              return true;
          }
  
          return super.onOptionsItemSelected(item);
      }
  
  }
  </code></pre>