[英]How do I make a 'button click action' on one page open the next in Android Studio using Navigation Graphical tool?
I'm new to Android Studio and Java programming.我是 Android Studio 和 Java 编程的新手。 I'm stuck trying to figure out how the graphical navigation Resource feature is used to link pages visually.
我一直在试图弄清楚如何使用图形导航资源功能来直观地链接页面。 I've made 2 pages for my app each with unique names (eg Page1 & Page2).
我为我的应用程序制作了 2 个页面,每个页面都有唯一的名称(例如 Page1 和 Page2)。 I've also been able to link the two pages visually by dragging and dropping the round circle in the Graphic Navigation panel and named the action (eg action 1).
通过在“图形导航”面板中拖放圆形并命名操作(例如操作 1),我还能够直观地链接两个页面。
I followed the solutions offered in this thread How do I get a button to open another activity?我遵循了此线程中提供的解决方案如何获取按钮以打开另一个活动? but none of them worked for me.
但他们都没有为我工作。
This is my button's code.这是我的按钮代码。
public class MainActivity extends AppCompatActivity {
private Button register_button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
register_button = (Button) findViewById(R.id.action_mainActivity_to_registration);
register_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
openRegistrationPage();
}
});
}
public void openRegistrationPage () {
Intent intent = new Intent(this, registration.class);
startActivity(intent);
}
}
I would want the next page to open when one button is clicked.我希望在单击一个按钮时打开下一页。
Make sure you declare your activities
in Manifest
file like this确保像这样在
Manifest
文件中声明您的activities
<activity android:name=".YOUR_ACTIVITY" />
And in you Button
action, make the navigation action like this在你的
Button
动作中,使导航动作像这样
Intent intent = new Intent(YOUR_ACTIVITY_1.this, YOUR_ACTIVITY_2.class);
startActivity(intent);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.