我正在从newboston学习 android .. 我想先显示一个菜单,如本教程中所示.. 我做了同样的事情,但不知道为什么菜单活动没有出现 .. 帮助我哪里做错了
这是我的代码
android manfiest.xml
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".Splash"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- 2nd activity -->
<activity
android:name="com.example.android.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.android.MainActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<!-- 3rd Activity Test -->
<activity
android:name=".Menu"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.android.Menu" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".TesxtPlay"
android:label="@string/app_name" >
</activity>
</application>
这是菜单类
public class Menu extends ListActivity {
//declaring above so both methods can access these
String classes[] = {"MainActivity","TextPlay","example2",
"example3","example4","example5","example6",};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Menu.this, android.R.layout.simple_list_item_1, classes));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
super.onListItemClick(l, v, position, id);
String cheese = classes[position];
Class ourClass;
try {
ourClass = Class.forName("com.example.android." + cheese);
Intent ourIntent = new Intent(Menu.this,ourClass);
startActivity(ourIntent);
}catch(ClassNotFoundException e){
e.printStackTrace();
}
}
}
文本播放类
public class TextPlay extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
Button chkCmd = (Button) findViewById(R.id.bResults);
final ToggleButton passTog = (ToggleButton) findViewById(R.id.tbPassword);
final EditText input = (EditText) findViewById(R.id.etCommands);
TextView display = (TextView) findViewById(R.id.display);
passTog.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(passTog.isChecked()){
input.setInputType(InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_VARIATION_PASSWORD);
}else{
input.setInputType(InputType.TYPE_CLASS_TEXT);
}
}
});
}
}
溅
public class Splash extends Activity {
MediaPlayer ourSong;
@Override
protected void onCreate(Bundle iloveyou) {
// TODO Auto-generated method stub
super.onCreate(iloveyou);
setContentView(R.layout.splash);
ourSong = new MediaPlayer().create(Splash.this, R.raw.kalimba);
ourSong.start();
Thread timer = new Thread(){
public void run(){
try{
sleep(5000);
}catch(InterruptedException e){
e.printStackTrace();
}finally{
//starting activity
Intent openMainActivityClass = new Intent("com.example.android.MainActivity");
startActivity(openMainActivityClass);
}
}
};
timer.start();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
ourSong.release();
finish();
}
}