何が問題なのかわかりません。1 つの activity_main.xml と main.xml を作成しました。main.xml は res/menu フォルダー内にありますが、エミュレーターで [メニュー] をクリックすると何も表示されません。
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>