gpt4 book ai didi

java - 当我第二次设置进度值时, donut 进度条值波动

转载 作者:行者123 更新时间:2023-12-01 09:59:26 24 4
gpt4 key购买 nike

我创建了一个 donut 进度条,我正在设置进度条值,并且第一次工作正常,但是当我第二次设置该值时,进度条在第一个值和第二个值之间波动,我想要进度条设置为与第二个值一致

here is my code :

strMalePercentage = jsonObject.getJSONObject("male").getString("percentage_manglik_present");
txtPercentage.setText("Manglik Male"+strMalePercentage);
Progress(strMalePercentage);

public void onClick(View v) {
int id = v.getId();
if (id == R.id.btn_ManglikMatchMale){
linearMale.setVisibility(View.VISIBLE);
linearFemale.setVisibility(View.GONE);

imgMatchGender.setBackgroundResource(R.drawable.ic_male1);
txtPercentage.setText("Manglik Male");
Progress(strMalePercentage);
btnMale.setBackgroundColor(getResources().getColor(R.color.textPrimary));
btnMale.setBorderColor(getResources().getColor(R.color.sky_blue));
btnFemale.setBackgroundColor(getResources().getColor(R.color.light_pink));
btnFemale.setTextColor(R.color.textPrimary);
btnMale.setTextColor(R.color.gray_light);
}else
{ linearMale.setVisibility(View.GONE);
linearFemale.setVisibility(View.VISIBLE);

imgMatchGender.setBackgroundResource(R.drawable.ic_female1);
txtPercentage.setText("Manglik Female ");
Progress(strFemalePercentage);
btnFemale.setBackgroundColor(getResources().getColor(R.color.textPrimary));
btnFemale.setBorderColor(getResources().getColor(R.color.light_pink));
btnMale.setBackgroundColor(getResources().getColor(R.color.sky_blue));
btnMale.setTextColor(R.color.textPrimary);
btnFemale.setTextColor(R.color.gray_light);

}

}


public void Progress(final String Percentage){
Timer timer;


donutProgress = (DonutProgress) findViewById(R.id.donut_progress_male);

timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
double d = Double.parseDouble(Percentage);
int i = (int) d;
donutProgress.setProgress(0);
donutProgress.setProgress(i);


}
});
}
},1000,100);
}

最佳答案

也许是这样的,所以计时器引用在外部,如果已经运行,您可以取消它

private Timer timer;

public void progress(final String Percentage){

donutProgress = (DonutProgress) findViewById(R.id.donut_progress_male);

if (timer == null) {
timer = new Timer();
} else {
timer.cancel();
}
timer.schedule(new TimerTask() {

@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
double d = Double.parseDouble(Percentage);
int i = (int) d;
donutProgress.setProgress(0);
donutProgress.setProgress(i);


}
});
}
},1000,100);
}

关于java - 当我第二次设置进度值时, donut 进度条值波动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36932781/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com