我想要我的按钮,当按下时,它将能够切换到另一个布局
按下按钮时如何启动另一个布局? 我遵循了一些网络解决方案,但它似乎对我没有帮助。
How can I launch another layout when button is pressed?
I followed some of the web's solution, but it doesn't seem to help me out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,如果您只是想更改整个 Activity 的视图,可以执行 setContentView(R.layout.newLayout) ,但这是一个非常糟糕的方法。
你应该做的是
startActivity(new Intent(context, NewActivity.class));
你会这样做:
虽然在未来,你真的应该在提出问题之前尝试做更多的研究像这样。当我刚接触 Android 时,我也有同样的问题,但 Google 和 StackOverflow 能够通过搜索答案来解决它。如果您仔细阅读的话,开发人员指南也会有所帮助。
Well, if you simply want to change the view for the entire Activity, you can do
setContentView(R.layout.newLayout)
but that is a really bad way to do it.What you should do instead is
startActivity(new Intent(context, NewActivity.class));
You would do that like this:
Though in the future, you really should try to do more research before asking a question like this. I had the same question when I was new to Android, but Google and StackOverflow were able to resolve it by searching for the answer. The Developer's Guide also helps if you peruse it enough.