Android Include File Equivalent
I have a menu that I want to implement on multiple activities. If I change the menu I don't want to have to update these everytime in every place
onCreateOptionsMenu()
or
onOptionsItemSelected()
Is there a way to include t开发者_Python百科hese sections in an activity and link it to a single file to edit the menu?
Option #1: Create your own subclass of Activity
, implement those methods there, then extend your custom subclass for your actual activities.
Option #2: Create static methods someplace that implement the logic contained in those methods. Have each of your activities delegate to the static methods. This is a bit more work, but it still consolidates the real business logic, and you don't have to worry about any inheritance issues.
精彩评论