Android SeekBarPreference

十年热恋 提交于 2019-11-28 01:14:09
Sileria

The problem with sliding here is due to notifyChange() call. That is interfering with the sliding somehow. I am also working on similar widget because I do not like the Dialog approach.

As promised here is the solution that I added to my open source project:

I have written a SeekBarPreference class that is embeded widget inside the preferences activity instead of popup dialog. You can download the jar file from:

http://aniqroid.sileria.com/

The class documentation and usage is here: http://aniqroid.sileria.com/doc/api/com/sileria/android/view/SeekBarPreference.html

Also do not forget to checkout the handy companion class to auto show a summary when you change the SeekBar: http://aniqroid.sileria.com/doc/api/com/sileria/android/event/PrefsSeekBarListener.html

Slider works in tutorial by changing onProgressChanged to

public void onProgressChanged( SeekBar seekBar, int progress, boolean fromUser )
{
    progress = Math.round( ( (float) progress ) / interval ) * interval;
    persistInt(progress);
    callChangeListener( progress );
    seekBar.setProgress( progress );
    this.monitorBox.setText( progress + "" );
    updatePreference( progress );
}

Regarding the inability to move the slider, this is because its width is set to 80 (see params2) which is too narrow to allow sliding. After setting a reasonable width for it, e.g. 400, and the associated text view and a few mods to get it to compile with my SDK version it worked for me. One advantage this version has over many others is that the layout is done in the code instead of XML which allows an app to easily instantiate multiple sliders.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!