public class menu extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity_page);
{
Button but1 = (Button)findViewById(R.id.imageButton4);
but1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.indore.indoreindicator.Busone"));
}
});
}
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
}
}
我的菜单类
中有这行代码busone课程 -
package com.indore.indoreindicator;
import android.app.Activity;
import android.os.Bundle;
public class Busone extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.busmenu);
}
}
Android清单文件
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.indore.indoreindicator"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.indore.indoreindicator.MainActivityPage"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".menu"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.Menu" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".Busone"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.indore.indoreindicaotr.Busone" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
主要活动页面 -
<ImageButton
android:id="@+id/imageButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="47dp"
android:layout_toLeftOf="@+id/TextView05"
android:src="@drawable/bus"
tools:ignore="ContentDescription" />
我的应用程序启动但在启动画面后失败,无法在第一页上移动。 但是如果我评论按钮编码部分,applcation会移动到菜单页面。
为什么我不能从我的菜单页面转到名为总线菜单的第二页?
答案 0 :(得分:2)
你应该尝试使用
startActivity(new Intent(getApplicationContext(), Busone.class);
而不是
startActivity(new Intent("com.indore.indoreindicator.Busone"));
答案 1 :(得分:1)
如果您只需要在布局之间切换,只需添加setOnClickListener
setContentView(R.layout.whatevername);
然后在此之后添加您的布局内容,如imageview,按钮等。只有当你需要为特定于布局的孩子添加另一个onClick时才这样做! 如果你想在活动“班级”之间切换,那么
Intent intent = new Intent(getApplication(), SecondClass.class);
startActivity(intent);
并且不要忘记在Android清单中添加您的其他活动
<activity android:name=".SecondClass"/>
基于您的CODE
查看编辑!!!
public class menu extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity_page);
**{** // why this is here ?????
Button but1 = (Button)findViewById(R.id.imageButton4);
but1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.indore.indoreindicator.Busone"));
}
});
**}** // why this is here ????
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
}
}
答案 2 :(得分:0)
试试这个:
startActivity(new Intent(menu.this, Busone.class));
答案 3 :(得分:0)
我不明白你要解释的是什么,但我看到的是你在xml布局中使用图像按钮并使用菜单类中的普通按钮。无需任何方式使用Image Button,只需使用android:background将图像设置为“普通”按钮即可。