Context
I have an application that contains a Activity
called MapActivity
(of which is a Map type activity that inherits from GoogleMaps api), and another Activity
common that will serve as a search with filters to refine the results that will appear in Activity
of the map.
My application has the minimum api version ( minSdkVersion ) as: 15 and has the target api version ( SdkTarget ) as: 22 (current)
Code
public class MapaFiltrosActivity extends ActionBarActivity implements ActionBar.TabListener {
SectionsPagerAdapter mSectionsPagerAdapter;
ViewPager mViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mapa_filtros);
final ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);
}
});
for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
switch (i){
case 0: actionBar.addTab(actionBar.newTab()
.setText(mSectionsPagerAdapter.getPageTitle(i))
.setTabListener(this)
); break;
case 1: actionBar.addTab(
actionBar.newTab()
.setText(mSectionsPagerAdapter.getPageTitle(i))
.setTabListener(new TabListener<MapFragment>(R.layout.activity_map, this, "Mapa", MapActivity.class))
); break;
}
}
}
}
In the code above, I just put the part that is inside the onCreate()
that I believe is where I can manipulate this activity call.
PageAdapter Code
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
return PlaceholderFragment.newInstance(position + 1);
}
@Override
public int getCount() {
//total pages
return 2;
}
@Override
public CharSequence getPageTitle(int position) {
Locale l = Locale.getDefault();
switch (position) {
case 0:
return getString(R.string.title_section1).toUpperCase(l);
case 1:
return getString(R.string.title_section2).toUpperCase(l);
}
return null;
}
}
Doubt
The question itself is that I can not assign a TabListener
to Tab
of ActionBar
, the way I'm doing it is as follows:
actionBar.addTab(
actionBar.newTab()
.setText(mSectionsPagerAdapter.getPageTitle(i))
.setTabListener(
new TabListener<MapFragment>(R.layout.activity_map, this, "Mapa", MapActivity.class))
);
The problem is with% w_that the compiler can not identify and can not suggest to change for another or to import some kind of library.
Detail is that I do not know if this way is correct, and if it is not, I would like to know: By what way could I assign an activity correctly to new TabListener()
of my Tab
?