I’m trying to use getInt to get an integer from my preferences so when the user selects a sport in the preferences it will set a different layout depending on which sport they pick
my java
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getPrefs.getInt("sports", 1)){
setContentView(R.layout.main);
}else if(getPrefs.getInt("sports", 1)){
setContentView(R.layout.hockey);
}else if(getPrefs.getInt("sports", 1)){
setContentView(R.layout.basketball);
}
my preference xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<ListPreference
android:entries="@array/list"
android:key="sports"
android:summary="Choose your sport"
android:title="Sports"
android:entryValues="@array/lValues"
android:defaultValue="1">
</ListPreference>
my array xml
<string-array name="list">
<item >
Soccer
</item>
<item >
Lacross
</item>
<item >
Hockey
</item>
<item >
VolleyBall
</item>
<item >
Basketball
</item>
</string-array>
<string-array name="lValues">
<item >
1
</item>
<item >
2
</item>
<item >
3
</item>
<item >
4
</item>
<item>
5
</item>
</string-array>
I get the error under
getPrefs.getInt("sports", 1)
The minimum sdk and the target sdk are both 10 if that makes a difference.
1 is different from true.
1 is an int while true is a boolean.
I guess you should do:
or
BTW, in your case, i would do: