gpt4 book ai didi

java - 搜索栏无法正常工作

转载 作者:行者123 更新时间:2023-11-30 03:34:51 27 4
gpt4 key购买 nike

每次我触摸它时,我都想从我的应用程序中的搜索栏中获取值。我在 seekbar 中声明的值将添加到我的 url 中,但每次我触摸 seekbar 时,它都会给我一个循环,并且 url 将循环并加载为 progressChanged 上的 seekbar 数量。这是我的代码:

int period = 0;
SeekTime.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}

@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
if (SeekTime.getProgress() <= 3){
SeekTime.setProgress(0);
period=7;
}
if (SeekTime.getProgress() > 3 && SeekTime.getProgress() <= 8) {
SeekTime.setProgress(5);
period =30;
}
if (SeekTime.getProgress() >8 && SeekTime.getProgress()<=13){
SeekTime.setProgress(10);
period = 90;
}
if (SeekTime.getProgress() >13 && SeekTime.getProgress()<=18){
SeekTime.setProgress(15);
period = 180;
}
if (SeekTime.getProgress() >18 && SeekTime.getProgress()<=23){
SeekTime.setProgress(20);
period = 270;
}
if (SeekTime.getProgress() >23){
SeekTime.setProgress(25);
period = 360;
}
new LoadData(URL+period).execute();

最佳答案

我认为您遇到的问题是因为当您调用 SeekTime.setProgress() 时进度正在改变 - 它再次调用 onProgressChange()。

您应该做的是检查进度更改是否由用户完成。您有 fromUser 变量可以控制它。

int period = 0;
SeekTime.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}

@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
if(fromUser) {
if (SeekTime.getProgress() <= 3){
SeekTime.setProgress(0);
period=7;
}
if (SeekTime.getProgress() > 3 && SeekTime.getProgress() <= 8) {
SeekTime.setProgress(5);
period =30;
}
if (SeekTime.getProgress() >8 && SeekTime.getProgress()<=13){
SeekTime.setProgress(10);
period = 90;
}
if (SeekTime.getProgress() >13 && SeekTime.getProgress()<=18){
SeekTime.setProgress(15);
period = 180;
}
if (SeekTime.getProgress() >18 && SeekTime.getProgress()<=23){
SeekTime.setProgress(20);
period = 270;
}
if (SeekTime.getProgress() >23){
SeekTime.setProgress(25);
period = 360;
}
new LoadData(URL+period).execute();
}
}

关于java - 搜索栏无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16766130/

27 4 0