I have a title bar in my application. And the title bar has one button. On click of that button I display info activity. Now, as far as I know, android:onClick needs a reference of a public method inside the activity which has the xml set in setContentView(). Now, as the logic for that buttons click will be the same throughout the application, so what I want is, I will the method just once say showInfoScreen(View view) and put it in that buttons onClick attribute. And I need not write the same method everywhere. Is it possible?
I have a title bar in my application. And the title bar has one
Share
Of course it’s possible. Write an
Activityclass, then have all of yourActivitys extend it. For example:Then all of your derived
Activitys would extendBaseActivityinstead ofActivity.The beauty of doing it this way is that any
Activitythat extends this class automatically gets this feature. No coding is required in the derived classes, just inBaseActivity. The only contract all of yourActivitys will have will be to haveR.id.buttonor whatever id you name it within its content.