I am trying to bring up a Preferences screen. Here is the XML for the
screen.
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<EditTextPreference
android:key="weight"
android:title="@string/weightlbltxt"
android:defaultValue="145"
/>
<ListPreference
android:title="@string/genderlbltxt"
android:entries="@array/genders"
android:defaultValue="Male"
/>
<ListPreference
android:title="string/alarmlbltxt"
android:entries="@array/alarms"
android:defaultValue="None"
/>
<EditTextPreference
android:key="BAC"
android:title="@string/baclbltxt"
android:defaultValue="0.08"
/>
<Button android:id="@+id/btnSetDone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="@string/donetxt"
/>
</PreferenceScreen>
Here is the matching Java:
package com.parisj13.trackmydrinks;
import android.content.Context;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.View.OnClickListener;
public class Settings extends PreferenceActivity implements
OnClickListener {
@Override
protected void onCreate(Bundle savedInstanceState){
super .onCreate(savedInstanceState);
addPreferencesFromResource(R.layout.settings);
//setContentView(R.layout.settings);
}
@Override
public void onClick(View v) {
finish();
}
public static int GetWeight(Context context){
return PreferenceManager.getDefaultSharedPreferences(context)
.getInt("weight", 145);
}
public static String GetGender(Context context){
return PreferenceManager.getDefaultSharedPreferences(context)
.getString("gender", "Male");
}
public static String GetAlarm(Context context){
return PreferenceManager.getDefaultSharedPreferences(context)
.getString("alarm", "None");
}
public static int GetBAC(Context context){
return PreferenceManager.getDefaultSharedPreferences(context)
.getInt("BAC", 145);
}
}
Manifest Entry:
<activity android:name=".Settings"
android:label="@string/app_name">
</activity>
The code that launches the Settings screen:
if(v.getId() == R.id.btnSettings){
i = new Intent(this, Settings.class);
startActivity(i);
return;
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---