我需要将按钮与页面(不是主页面)链接,就像我点击按钮转到页面一样(位置页面)?
private void setupLocationPageButton() {
Button LocationPageButton = (Button) findViewById(R.id.btnLocationPage);
LocationPageButton.setOnClickListener(new View.OnClickListener()
答案 0 :(得分:4)
如果你的目标是打开另一项活动,那么这就是你想要做的事情。
在您的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" />
...
然后在你想要的活动中
public void onButtonClicked(View view) {
Intent intent = new Intent(this, OtherActivity.class);
startActivity(intent);
}
答案 1 :(得分:2)
我认为您尝试做的事情是:当您点击按钮时,它会更改MainActivity
Button LocationPageButton = (Button) findViewById(R.id.btnLocationPage);
LocationPageButton.setOnClickListener(new View.OnClickListener({
public void onClick(View _view) {
Intent i = new Intent(MainActivity.this,TheActivityTheclassNameYouWannGoTo.class);
startActivity(i);
}
}));
但首先你需要创建活动,并且类继承像MainActivity这样的活动
在AndroidMainfest.xml中初始化类
我希望这可以帮到你
答案 2 :(得分:0)
您可以使用片段,每个片段都包含一个特定页面,请参阅this获取Android片段。