{"id":3876,"date":"2014-03-30T06:10:23","date_gmt":"2014-03-30T06:10:23","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/reusing-views-on-multiple-activites-in-android-collection-of-common-programming-errors\/"},"modified":"2014-03-30T06:10:23","modified_gmt":"2014-03-30T06:10:23","slug":"reusing-views-on-multiple-activites-in-android-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/reusing-views-on-multiple-activites-in-android-collection-of-common-programming-errors\/","title":{"rendered":"Reusing views on multiple activites in Android-Collection of common programming errors"},"content":{"rendered":"<p>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&#8217;t ask me why, that was the request \ud83d\ude42 Having these buttons do the same thing in all screens I thought like this:<\/p>\n<ol>\n<li>Put the layout in a xml file and it in all my activities layout<\/li>\n<li>Create a class that extends Activity and assign onClick methods for all my buttons<\/li>\n<li>When a ToggleButton is checked, set all other buttons checked=&#8221;false&#8221; and perform the button&#8217;s operation.<\/li>\n<\/ol>\n<p>I am stuck on my BaseActivity, when overriding onCreate(). How do I get a hold of my buttons and assign onClick listeners to them ?<\/p>\n<pre><code>public class BaseActivity extends Activity {\n    private ToggleButton menuHome;\n\n    @Override\n    public void onCreate(Bundle savedInstanceState) {\n             \/\/this does not work as it cannot find R.id.menu_home)\n        menuHome = (ToggleButton) findViewById(R.id.menu_home);\n    }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;t ask me why, that was the request \ud83d\ude42 Having these buttons do the same thing in all screens I thought like this: Put the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3876","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3876","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3876"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3876\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3876"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3876"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3876"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}