I have the following scenario: android up, compatible starting with android 1.6 and up. At the bottom of ALL activities I have a set of ToggleButtons that only start activities. Don’t ask me why, that was the request 🙂 Having these buttons do the same thing in all screens I thought like this:
- Put the layout in a xml file and it in all my activities layout
- Create a class that extends Activity and assign onClick methods for all my buttons
- When a ToggleButton is checked, set all other buttons checked=”false” and perform the button’s operation.
I am stuck on my BaseActivity, when overriding onCreate(). How do I get a hold of my buttons and assign onClick listeners to them ?
public class BaseActivity extends Activity {
private ToggleButton menuHome;
@Override
public void onCreate(Bundle savedInstanceState) {
//this does not work as it cannot find R.id.menu_home)
menuHome = (ToggleButton) findViewById(R.id.menu_home);
}
}
In your other Activities that extend BaseActivity take a look at your OnCreate method. Does it look like this?
It has to do with the order… you haven’t set the content view so your toggle button doesn’t exist. Try this: