我不明白是什么问题,我已经创建了一个activity_main.xml和main.xml,main.xml位于res / menu文件夹中,但是当我在模拟器中点击“MENU”时它什么都没显示.. < / p>
package com.sscet.womenssafety;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
public class MainActivity extends Activity {
ImageButton ib1;
int timeonetwo;
public void gettime(Alarmsettings a)
{
timeonetwo= a.getTimeone();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Handler handler=new Handler();
final MediaPlayer mp=MediaPlayer.create(getApplicationContext(),R.raw.alarm );
ib1=(ImageButton) findViewById(R.id.settings);
ib1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mp.start();
if(timeonetwo==15){
handler.post(new Runnable(){
public void run(){
if(mp.getCurrentPosition()>15000)
mp.stop();
}
});}
if(timeonetwo==30){
handler.post(new Runnable(){
public void run(){
if(mp.getCurrentPosition()>30000)
mp.stop();
}
});}
if(timeonetwo==45){
handler.post(new Runnable(){
public void run(){
if(mp.getCurrentPosition()>45000)
mp.stop();
}
});}
if(timeonetwo==60){
handler.post(new Runnable(){
public void run(){
if(mp.getCurrentPosition()>60000)
mp.stop();
}
});}
}
});
}
@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 boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.contact_settings:
Intent int1 =new Intent(MainActivity.this, Alarmsettings.class);
startActivity(int1);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
这是MAIN.XML
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<Item
android:id="@+id/contact_settings"
android:icon="@drawable/icon_contact"
android:title="@string/contact_settings"/>
<Item
android:id="@+id/camera_settings"
android:icon="@drawable/icon_camera"
android:title="@string/camera_settings"/>
<Item
android:id="@+id/sms_settings"
android:icon="@drawable/icon_sms"
android:title="@string/sms_settings"/>
<Item
android:id="@+id/alarm_settings"
android:icon="@drawable/icon_alarm"
android:title="@string/alarm_settings"/>
</menu>
答案 0 :(得分:1)
一篇很晚的帖子,但是:
在模拟器中运行时按F2键切换菜单显示(类似于按设备上的菜单按钮)。如果将Android3.0 +用作模拟操作系统
,则标准模拟器上的菜单按钮不起作用