Reputation: 1571
I'm trying to modify a tutorial, about swipes and tabs, so I can manually set the Tablistener method for each tab, which I insert into the action bar. The reason for this is, I want to be able to edit each Fragment file seperately (now they are created dynamically).
The code from the tutorial for dynamically setting the Tablistener for a specific tab:
for (int i = 0; i < mCollectionPagerAdapter.getCount(); i++) {
actionBar.addTab(actionBar.newTab()
.setText(mCollectionPagerAdapter.getPageTitle(i))
.setTabListener(this)); //this is of type FragmentActivity
}
I want to change this by manually specifying the Tablistener for every tab. Example:
Tab tab = actionBar.newTab();
tab.setText("tabName");
tab.setTabListener(new TabListener<Tab1Fragment>(this, "tabName", Tab1Fragment.class));
// the first parameter should be an Activity object, but mine is a FragmentActivity
actionBar.addTab(tab);
When I try the above code I get two errors:
What could be done to resolve this?
Upvotes: 0
Views: 3431
Reputation: 361
Try to put these two imports on the top of your java file (after package definition):
import android.app.ActionBar;
import android.app.ActionBar.Tab;
It worked for me ;)
Upvotes: 2
Reputation: 1335
As you can see in the official documentation, ActionBar.TabListener is an interface so you must implement it.
Upvotes: 0