eclipse 如何使按钮重定向到另一个 xml 页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14655849/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to make a button redirect to another xml page
提问by Mr.Cosmic
I'm making a button in xml, like this:
我正在 xml 中制作一个按钮,如下所示:
<Button
android:id="@+id/buttondp"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/thisisstringtext" />
and I want it to direct it to another page coded in xml. Can anyone help me out?
我希望它将它定向到另一个用 xml 编码的页面。谁能帮我吗?
回答by FoamyGuy
Make another activity and use
进行另一项活动并使用
setContentView(R.layout.your_other_layout);
inside of it.
在它里面。
Then in the onClickListener for your button put this:
然后在您的按钮的 onClickListener 中放置:
Intent i = new Intent(YourActivity.this, YourOtherActivity.class);
startActivity(i);
回答by Schlacter James
You can add the onclick listener to your button, so: android:onclick="method_in_your_activity"
.
你可以的onclick监听器添加到您的按钮,所以:android:onclick="method_in_your_activity"
。
In your activity added the method (method_in_your_activity) and add startActivity(NewActivity)
.
在您的活动中添加了方法 (method_in_your_activity) 并添加startActivity(NewActivity)
.
回答by Anirudha Agashe
You can use different activities for different layout. But if you want to use same activity for different layout then you should go for ViewFlipper
. You can also get some animation when switching from one view to another. Tutorial regarding the same can be found here.
您可以为不同的布局使用不同的活动。但是,如果您想对不同的布局使用相同的活动,那么您应该选择ViewFlipper
. 从一个视图切换到另一个视图时,您还可以获得一些动画。可以在此处找到有关相同的教程。
回答by MahendraSingh Juni
using this code in java file you will click button to redirect next page
在 java 文件中使用此代码,您将单击按钮重定向下一页
public void onClick(View v) {
public void onClick(View v) {
Intent ia=new Intent(getApplicationContext(),second.class);
startActivity(ia);
}
回答by Akhil V Suku
In your button XML, add :
在您的按钮 XML 中,添加:
android:onCLick="myRedirectFunction"
In your MyMainActivity.java, add function named myRedirectFunction and inside that function :
在您的 MyMainActivity.java 中,添加名为 myRedirectFunction 的函数并在该函数内:
Intent homepage = new Intent(MyMainActivity.this, MySubActivity.class);
startActivity(homepage);
回答by JoxTraex
If you dynamically want to change the Content of your activity you can always call setContentView(my_layout)
and change the content. However; its best practice to use another Activity.
如果您想动态地更改活动的内容,您可以随时调用setContentView(my_layout)
并更改内容。然而; 使用另一个活动的最佳实践。