【发布时间】:2013-10-09 11:05:15
【问题描述】:
好的,我的 android 应用程序主页上有多个按钮。
在编写这样的应用程序时,我似乎一直感到困惑。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void aboutus (final View view) {
setContentView(R.layout.aboutus);
System.out.println("about us clicked");
}
我已经在 xml 中添加了 on click。
但是,我需要在“关于我们”页面中编写代码。
在关于我们的课程中,我有以下内容
public class AboutUs extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.aboutus);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void onBackPressed() {
setContentView(R.layout.activity_main);
}
}
这里是被点击按钮的xml代码
<ImageButton
android:id="@+id/ImageButton01"
android:layout_width="134dp"
android:layout_height="97dp"
android:layout_x="16dp"
android:layout_y="150dp"
android:onClick="aboutus"
android:src="@drawable/aboutus" />
我正在编写的任何代码在该页面上都不起作用?我不知道为什么?有人可以帮忙吗?
谢谢。
【问题讨论】:
-
我不清楚你的问题,你在 xml 中添加 onClick 吗?那么当你点击那个按钮时会发生什么?
-
抱歉,当我单击按钮时,会加载正确的 xml 页面。但是按钮单击类中的所有代码都不起作用? @Monica Ive 发布了我的 xml
-
好吧,这不是你在android中改变视图的方式,如果你想导航到另一个视图,你需要启动另一个
Activity,你会这样做。 How to navigate from one screen to another screen 和博客条目 Android Activity – From One Screen To Another Screen -
你需要改变你的代码结构。
-
NARESH REDDY 是正确的检查他的答案,并在清单中添加你的其他类