I'm trying to set up a onTabChangedListner()
and I've looked around Stack Overflow and some other sites and it's pretty much the same thing everywhere so I copied that code. Here's my current code(this is all within on onCreate()
)
getTabHost().setOnTabChangedListner(new onTabChangeListner() {
@Override
public void onTabChanged(String tabId) {
Toast.makeText(this, "A new tab has been selected", Toast.LENGHT_SHORT).show();
}
});
I'm getting 3 errors:
Unknown entity
OnTabChangeListner()
There is no applcable method to
(com.mycompany.myapp.MainActivity.(anonymous), java.lang.String,int)
Method
android.widget.TabHost.setOnTabChangedListner(android.widget.TabHost.OnTabChangeListner) in 'android.widget.TabHost'can not be applied to (com.mycompany.myapp.MainActivity.(anonymous))
Any help would be appreciated!
Update: Here is my entire onCreate followed by a onTabChanged method:
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);
TabHost tabHost = getTabHost();
TabSpec cat1spec = tabHost.newTabSpec("Category 1");
cat1spec.setIndicator("Category 1");
cat1spec.setContent(R.id.tab1c);
TabSpec cat2spec = tabHost.newTabSpec("Category 2");
cat2spec.setIndicator("Category 2");
cat2spec.setContent(R.id.tab2c);
TabSpec cat3spec = tabHost.newTabSpec("Favourites");
cat3spec.setIndicator("Favourites");
cat3spec.setContent(R.id.tab3c);
tabHost.addTab(cat1spec);
tabHost.addTab(cat2spec);
tabHost.addTab(cat3spec);
getActionBar().setHomeButtonEnabled(true);
tabHost.setOnTabChangedListener(this);
}
@Override
public void onTabChanged(String tabId) {
//Something will happends here
}