开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜