I'd like to display the value of the seekbar when the user moves it, similar to the way the Contacts ListView displays the letter of the section you're in when you scroll it (Android 2.3.x).
Anyone have a suggestion of how to implement it? I was thinking a Toast in onProgressChanged() method of OnSeekBarChangeListener but having trouble getting the context to show() the Toast.
EDIT: Also, the Seekbar is in a row of a ListView so OnSeekBarChangeListener is in a class extendending ArrayAdapter and not the usual "Activity" so things like getBaseContext() are not available to the method.
you can use :
Toast.makeText(Main.this, "Message", Toast.LENGTH_LONG).show();
or
Toast.makeText(getBaseContext(), "Message", Toast.LENGTH_LONG).show();
First way:use Application
class globally
public class MyApp extends Application {
private static MyApp instance;
public static MyApp getInstance() {
return instance;
}
public static Context getContext(){
return instance.getApplicationContext();
}
@Override
public void onCreate() {
super.onCreate();
instance = this;
}
}
Second way:
Pass Context
to your class constructor or to a method in class
Thanks for the replies. I used a little from both suggestions and came up with this, but even at 500ms the Toast doesn't update fast enough to keep up with the seekBar changes. hm...
public class adapListControl extends ArrayAdapter <String>
{
final Context mCtx;
...
public adapListControl (Context context, int textViewResourceId)
{
super (context, textViewResourceId);
this.mCtx = context;
}
...
OnSeekBarChangeListener osbl = new OnSeekBarChangeListener ()
{
@Override
public void onProgressChanged (SeekBar seekBar, int progress, boolean fromUser)
{
Log.d (TAG, " prog change:" + progress);
Toast.makeText(mCtx, "" + progress, 500).show();
}
...
}