Hi Stoyan,
Yesterday I also asked myself if there's a Seekbar preference but I looked
around and did not find any so I created my own. Here's my code if it will
help you.
public class SeekBarPreference extends DialogPreference{
private Context context;
private SeekBar volumeLevel;
public SeekBarPreference(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
}
protected void onPrepareDialogBuilder(Builder builder) {
LinearLayout layout = new LinearLayout(context);
layout.setLayoutParams(new
LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
layout.setMinimumWidth(400);
layout.setPadding(20, 20, 20, 20);
volumeLevel = new SeekBar(context);
volumeLevel.setMax(8);
volumeLevel.setLayoutParams(new
ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
volumeLevel.setProgress(0); *// You might want to fetch the value
here from sharedpreferences*
layout.addView(volumeLevel);
builder.setView(layout);
super.onPrepareDialogBuilder(builder);
}
protected void onDialogClosed(boolean positiveResult) {
if(positiveResult){
persistString(volumeLevel.getProgress()+"");
}
}
}
then in your activity you can use this class:
SeekBarPreference sb = new SeekBarPreference(this, null);
sb.setTitle(R.string.volume);
sb.setSummary(R.string.volume_summary);
sb.setKey(VOLUME_LEVEL_PREF);
-Marc
On Fri, Jan 9, 2009 at 9:13 AM, Stoyan Damov <[email protected]> wrote:
>
> Hi guys,
>
> The emulator and G1's Settings apps apparently launches a preference
> activity.
> In Settings, Sound and Display, when you touch the "Ringer volume"
> setting, a dialog pops up, which shows a SeekBar.
> My question is how is this implemented because I need a similar (seek
> bar-driven) setting in my app.
>
> I don't have Android's source code and am hesitant to download 2.1G
> just to check :(
> I'm guess this setting does NOT launch an intent which pops up the
> dialog (because I'd expect that intent to be wrapped in
> PreferenceScreen and then I'd see the circled arrow indicator) but
> can't be sure.
> I know many people on the list are Google employees and am hoping I'll
> get an answer.
>
> Thanks in advance,
> Stoyan
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" 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-developers?hl=en
-~----------~----~----~----~------~----~------~--~---