Android SeekBar设置进度值

编程入门 行业动态 更新时间:2024-10-25 08:24:39
本文介绍了Android SeekBar设置进度值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

每当我单击按钮时,我都希望更改SeekBar进度.使用setProgress()仅适用于初始值.如果在进行一些更改后使用它,则会引发错误.

I want the SeekBar progress to change whenever I click a button. Using setProgress() works only for initial value. It throws an error if I use it after some changes.

推荐答案

也许您应该尝试使用处理程序?我在我的一个应用程序中使用了它,并且工作正常.

Perhaps you should try to use a handler? I use this in an app of mine and works fine.

1)创建SeekBar时:

1) When creating your SeekBar:

// ... seekBarHandler = new Handler(); // must be created in the same thread that created the SeekBar seekBar = (SeekBar) findViewById(R.id.my_seekbar); // you should define max in xml, but if you need to do this by code, you must set max as 0 and then your desired value. this is because a bug in SeekBar (issue 12945) (don't really checked if it was corrected) seekBar.setMax(0); seekBar.setMax(max); seekBar.setProgress(progress); // ...

2)单击您的按钮

// ... seekBarHandler.post(new Runnable() { @Override public void run() { if (seekBar != null) { seekBar.setMax(0); seekBar.setMax(max); seekBar.setProgress(newProgress); } } }); // ...

更多推荐

Android SeekBar设置进度值

本文发布于:2023-10-08 02:48:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1471290.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:进度   Android   SeekBar

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!