Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Android:problems creating settings menu

  • 10-07-2013 10:59PM
    #1
    Closed Accounts Posts: 1,235 ✭✭✭


    Hi,
    I keep getting a force close every time I click on settings in the action bar> ive been looking at stack overflow+the android dev website and have confused myself into a hole :)
    Here's the code for onOptionsItemSelected().Creating the intent causes the force close.
    public boolean onOptionsItemSelected(MenuItem item) {
    	    // Handle item selection
    	    switch (item.getItemId()) {
    	        case R.id.action_settings:
    	           // this code causes force close when settings is touched in actionbar
    	        	Intent settingsIntent = new Intent(this, Preferences.class);
    	            this.startActivity(settingsIntent);
    	            return true;
    	        case R.id.action_about:
    	            showAbout();
    	            return true;
    	        default:
    	            return super.onOptionsItemSelected(item);
    	    }
    	}
    

    And here,s the code for the Preferences class
    public class Preferences extends PreferenceActivity {
     
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            
            addPreferencesFromResource(R.xml.preferences);
        }
        
    }
    

    and heres the preferences.xml
    <?xml version="1.0" encoding="utf-8"?>
    
    <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
            <PreferenceCategory
                    android:title="Blinds">
                     <EditTextPreference
                    android:name="SmallBlindsEditText Preference"
                    android:summary="This allows you to change small blind amount"
                    android:defaultValue="Nothing"
                    android:title="Small Blind"
                    android:key="SmallBlindTextPref" />
                     
                     <RingtonePreference
                    android:name="Multiplier Preference"
                    android:summary="Change blind multiplier"
                    android:title="Multiplier"
                    android:key="multiplierPref" /> 
                    
            </PreferenceCategory>
            
    </PreferenceScreen>
    

    Now from looking at the android dev notes(and eclipse points out)that addPreferencesFromResource(R.xml.preferences) has been deprecated and that I should use PreferenceFragments but when I follow the examples I get a message saying they are for api 11 (and not 8 which my app is aimed at)

    Like I said I'm not sure where i'm goin wrong,any help much appreciated


Comments

  • Closed Accounts Posts: 1,235 ✭✭✭returnNull


    I seemed to have got it sorted just by removing the 2nd option in my preferences,xml and cleaned and rebuilt the project


  • Registered Users, Registered Users 2 Posts: 2,347 ✭✭✭Kavrocks


    In future you should paste the LogCat output too. It'll tell somebody what has gone wrong and generally where so they can help you easier and quicker.


Advertisement