Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid- Swiping in action bar tabs not working
    text
    copied!<p>I have written this code to perform horizontal swiping between the action bar tabs. But the listener does not even get called. here is the code-</p> <pre><code>@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setupTabs(); pager = (ViewPager) findViewById(R.id.pager); pager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { // When swiping between pages, select the // corresponding tab. System.out.println("in"); getActionBar().setSelectedNavigationItem(position); } }); } private void setupTabs() { ActionBar bar = getSupportActionBar(); bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); ActionBar.Tab tab1 = bar.newTab(); tab1.setText(R.string.tab_live); tab1.setTabListener(new MyTabListener()); ActionBar.Tab tab2 = bar.newTab(); tab2.setText(R.string.tab_tech_13); tab2.setTabListener(new MyTabListener()); ActionBar.Tab tab3 = bar.newTab(); tab3.setText(R.string.tab_tech_14); tab3.setTabListener(new MyTabListener()); ActionBar.Tab tab4 = bar.newTab(); tab4.setText(R.string.tab_map); tab4.setTabListener(new MyTabListener()); ActionBar.Tab tab5 = bar.newTab(); tab5.setText(R.string.tab_contacts); tab5.setTabListener(new MyTabListener()); bar.addTab(tab1, POS_LIVE,true); bar.addTab(tab2, POS_TECH_13); bar.addTab(tab3, POS_TECH_14); bar.addTab(tab4, POS_MAP); bar.addTab(tab5, POS_CONTACTS); // bar.addTab(tab2, POS_COMPT); // bar.addTab(tab3, POS_EVENTS); } private class MyTabListener implements ActionBar.TabListener { @Override public void onTabSelected(Tab tab, FragmentTransaction ft) { switch (tab.getPosition()) { case POS_TECH_13: FragmentTech13 frag1 = new FragmentTech13(); ft.replace(android.R.id.content, frag1); break; case POS_TECH_14: FragmentTech14 frag2 = new FragmentTech14(); ft.replace(android.R.id.content, frag2); break; case POS_CONTACTS: FragmentContacts frag3 = new FragmentContacts(); ft.replace(android.R.id.content, frag3); break; case POS_LIVE: FragmentLive fraglive = new FragmentLive(); ft.replace(android.R.id.content, fraglive); fraglive.setLiveUpdateListener(ActivityMain.this); break; } } </code></pre> <p>Here is the xml file of the above <code>MainActivity</code>-</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent" /&gt; </code></pre> <p>The <code>setOnPageChangeListener</code> is not even getting called here when i try to change the view.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload