gpt4 book ai didi

java - Android点击按钮跳转到另一个页面?

转载 作者:行者123 更新时间:2023-11-29 07:04:39 25 4
gpt4 key购买 nike

我需要将按钮与页面(不是主页)链接起来,例如当我单击按钮转到页面(位置页面)时?

private void setupLocationPageButton() {

Button LocationPageButton = (Button) findViewById(R.id.btnLocationPage);
LocationPageButton.setOnClickListener(new View.OnClickListener()

最佳答案

如果您的目标是打开另一个 Activity ,这就是您想要做的。

在你的 xml 文件中你会想要这样的东西

...

<Button
android:id="@+id/activity_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onButtonClicked"
android:text="@string/text_of_button" />

...

然后在你想要的 Activity 中

public void onButtonClicked(View view) {

Intent intent = new Intent(this, OtherActivity.class);
startActivity(intent);

}

关于java - Android点击按钮跳转到另一个页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21242137/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com