使用java包含在android中
我有一个包含 4 个按钮的标题视图。当我单击这 4 个按钮中的每一个时,它应该启动四个不同的活动。我还希望这些按钮出现在我的应用程序的每个视图中。
我可以使用 include 标签包含此标题视图。但是我怎样才能在每个活动中包含java代码(按钮点击等)呢?
谢谢
I have a header view which contains 4 buttons. When I click each of these 4 buttons it should start four different activities. And also I want these buttons in every view of my application.
I can include this header view using include tag. But how can I include the java code (button click etc) in every activities?
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
创建一个单独的类,它将获取按钮作为参数,并创建和设置适当的 onClick 侦听器。然后只需从您需要的地方调用班级即可。像这样:
在您的活动中:
Make a separate class which will get the buttons as parameters and which will create and set the appropriate onClick listeners. Then just call the class from where you need. Like this:
in your activity: