开发者

Android Include File Equivalent

开发者 https://www.devze.com 2023-02-20 11:26 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消