多个 SeekBars 监听器
我在同一视图上有多个搜索栏:
barheures = (SeekBar)findViewById(R.id.barheures); // make seekbar object
barheures.setOnSeekBarChangeListener(this); // set seekbar listener.
// since we are using this class as the listener the class is "this"
barminutes = (SeekBar)findViewById(R.id.barminutes);
barminutes.setOnSeekBarChangeListener(this);
这是侦听器:
@Override
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) {
// TODO Auto-generated method stub
Log.v("", "" + bar);
textMinutes.setText("" + progress + "Minute(s)" );
textHours.setText("" + progress + "Heure(s)" );
}
如果第一个或第二个栏已移动到同一个侦听器中,我想做一些不同的事情(这是好的做法吗?),但如何做?我的应用程序无法执行我想要的操作
I have multiple seekbar on the same view :
barheures = (SeekBar)findViewById(R.id.barheures); // make seekbar object
barheures.setOnSeekBarChangeListener(this); // set seekbar listener.
// since we are using this class as the listener the class is "this"
barminutes = (SeekBar)findViewById(R.id.barminutes);
barminutes.setOnSeekBarChangeListener(this);
And here is the listener:
@Override
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) {
// TODO Auto-generated method stub
Log.v("", "" + bar);
textMinutes.setText("" + progress + "Minute(s)" );
textHours.setText("" + progress + "Heure(s)" );
}
I wanna make something different if the first OR the second bar have moved into the same listener (is it the good practice?), but how to?? Here I have the app that don't do what I want
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
现在你有 2 个具有以下 id 的搜索栏:
现在在 onProgressChanged(SeekBar bar, intprogress, boolean fromUser) 方法中,执行以下操作:
Now then you have 2 seekbars with the following ids:
Now in the onProgressChanged(SeekBar bar, int progress, boolean fromUser) method, Do the following:
您也可以只检查 SeekBar 对象是否相等,而不是比较资源 id。示例:
我更喜欢这样做,因为这样您只需引用每个 SeekBar 资源的 id 一次(在
onCreate
中)。Instead of comparing resource ids, you can also just check the SeekBar object for equality. Example:
I prefer doing it this way because then you only ever reference the id of each SeekBar resource once (in your
onCreate
).