chuyauchi 0 Newbie Poster

My Android preference (menu) is not opening a new activity. When I click the 'menu' button on the emulator, I can see my 'Setting' option. However, when I click the 'Setting', the setting page is not showing.

There is no error and warning. Thank you for your time. I am still new on Android application development. I spent 3 hours on solving but I haven't figured out.

MainActivity.java

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);             //initialize a black form
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void onResume(){
        super.onResume();

        TextView msg = (TextView) findViewById(R.id.textView1);
        ImageView image = (ImageView) findViewById(R.id.image1);

        if (SettingsGlobal.getPlayerIndex() == 1)
        {
            msg.setText(R.string.msg1);
            image.setImageResource(R.drawable.player_1);

        }
        if (SettingsGlobal.getPlayerIndex() == 2)
        {
            msg.setText(R.string.msg2);
            image.setImageResource(R.drawable.player_2);

        }
        if (SettingsGlobal.getPlayerIndex() == 3)
        {
            msg.setText(R.string.msg3);
            image.setImageResource(R.drawable.player_3);

        }

    }

    @Override                                           //pop up the menu
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main_menu, menu);
        return true;
    }

    public boolean onOptionItemSelected(MenuItem item)
    {
        switch (item.getItemId())
        {
        case R.id.menu_settings:
            openSettingsActivity();
            return true;

            default:
                return super.onOptionsItemSelected(item);
        }
    }

    public void openSettingsActivity()
    {
            Intent startNewActivityOpen = new Intent(MainActivity.this,Settings.class);
            //Intent startNewActivityOpen = new Intent(MainActivity.this,SettingsGlobal.class);
            startActivityForResult(startNewActivityOpen, 0);

    }
}

Settings.java

public class Settings extends Activity implements OnItemSelectedListener{

    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.settings);

        Spinner spinner = (Spinner) findViewById(R.id.spinner1);
        spinner.setOnItemSelectedListener(this);
    }


    public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3){
        switch (arg2){
        default:
            SettingsGlobal.setPlayerIndex(arg2+1);
            return;
        }
    }

    public void onNothingSelected(AdapterView<?> arg0){
        // TODO Auto-generated method stub 
    }
}

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.chrischu.inclassassignment_3"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="10" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="Settings"></activity>
    </application>

</manifest>