简体   繁体   English

如何使用导航图形工具在 Android Studio 中打开一个页面上的“按钮单击操作”?

[英]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.

相关问题 Android Studio:使按钮打开下一个活动 - Android Studio: Make a Button open Next Activity 我每次使用Android Studio按下按钮时如何使1个按钮播放随机声音 - How do i make 1 button play random sounds each time i press the button using android studio Android Studio 导航抽屉与片段。 工具栏隐藏在下一个片段活动或页面中 - Android Studio navigation drawer with fragments. Tool Bar Hidden in next fragment Activity or page 如何获得在Android Studio中打开新活动的按钮? - How do i get a button to open a new activity in android studio? 如何使按钮在Android中执行操作 - How to make a button do an action in Android 如何使用 Java 编程语言制作退出 Android Studio 中的应用程序的按钮? - How do I make a button that quits the application in Android Studio using the Java programming language? 能够单击按钮,但未打开下一页 - Able to Click on button but next page not open 如何在Android Studio项目中使用代号一个迁移工具? - How do I use the codename one migration tool on my Android Studio project? 如何在 Android Studio 中的按钮单击上创建一个新按钮? - How to make a new button on a button click in Android Studio? 如何在 Android Studio 中制作“如果单击按钮,则执行此操作”? - How to make 'if button clicked, do this' in Android Studio?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM