Не могли бы вы рассказать, как быть с циклом AppCompatSeekBar внутри цикла for в Android?
У меня есть пример, аналогичный приведенному ниже коду, откуда я получаю это исключение:
java.lang.RuntimeException: невозможно запустить действие ComponentInfo {br.com.tribanco.empresarial / br.com.tricard.empresarial.ui.majoracaolimite.MajoracaoLimiteActivity}: java.lang.ClassCastException: android.view.AbsSavedStateбыть приведенным к android.widget.ProgressBar $ SavedState
Код:
final AppCompatSeekBar appCompatSeekBar = new AppCompatSeekBar(this);
int idSeekBarValor = 10;
appCompatSeekBar.setId(idSeekBarValor);
Drawable progressDrawable = getResources().getDrawable(R.drawable.seek_bar_global_style);
appCompatSeekBar.setProgressDrawable(progressDrawable);
progressDrawable = getResources().getDrawable(R.drawable.seek_bar_global_style);
appCompatSeekBar.setThumb(progressDrawable);
params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(25,4,25,0);
params.addRule(RelativeLayout.BELOW, id5);
appCompatSeekBar.setLayoutParams(params);
relativeLayout.addView(appCompatSeekBar, params);
appCompatSeekBar.setEnabled(false);
appCompatSeekBar.setMax(this.aumentoConcedido);
appCompatSeekBar.incrementProgressBy(stepProgress);
appCompatSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
progress = progress / stepProgress;
progress = progress * stepProgress;
seekBarValorGlobal = progress;
Log.i("teste", "onProgressChanged: " + seekBarValorGlobal);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
int prevTextViewId = idSeekBarValor;
int i=1;
for(final ContaDTO contaDTO : contaDTOs) {
curTextViewId++;
final AppCompatSeekBar appCompatSeekBarValorCartao = new AppCompatSeekBar(this);
int idSeekBarValorCartao = curTextViewId;
appCompatSeekBarValorCartao.setId(idSeekBarValorCartao);
Drawable progressDrawableCartao = getResources().getDrawable(R.drawable.seek_bar_style);
appCompatSeekBarValorCartao.setProgressDrawable(progressDrawableCartao);
appCompatSeekBarValorCartao.setThumb(ContextCompat.getDrawable(this, R.color.colorTransparent));
params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(25,4,25,0);
params.addRule(RelativeLayout.BELOW, idRelativeLayoutCartao);
appCompatSeekBarValorCartao.setLayoutParams(params);
relativeLayout.addView(appCompatSeekBarValorCartao, params);
curTextViewId++;
final AppCompatSeekBar appCompatSeekBarValorHiddenCartao = new AppCompatSeekBar(this);
final int idSeekBarValorHiddenCartao = curTextViewId;
appCompatSeekBarValorHiddenCartao.setId(idSeekBarValorHiddenCartao);
appCompatSeekBarValorHiddenCartao.setProgressDrawable(ContextCompat.getDrawable(this, R.color.colorTransparent));
progressDrawableCartao = getResources().getDrawable(R.drawable.ic_seek_bar_drawable);
appCompatSeekBarValorHiddenCartao.setThumb(progressDrawableCartao);
params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(25,4,25,0);
params.addRule(RelativeLayout.BELOW, idRelativeLayoutCartao);
appCompatSeekBarValorHiddenCartao.setLayoutParams(params);
relativeLayout.addView(appCompatSeekBarValorHiddenCartao, params);
final int valorMap = i;
appCompatSeekBarValorCartao.setMax(this.maxSeekBarValueGlobal - this.minSeekBarValueGlobal);
appCompatSeekBarValorCartao.incrementProgressBy(stepProgress);
appCompatSeekBarValorHiddenCartao.setProgress(0);
appCompatSeekBarValorHiddenCartao.setMax(this.aumentoConcedido);
appCompatSeekBarValorHiddenCartao.incrementProgressBy(stepProgress);
appCompatSeekBarValorHiddenCartao.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
progress = progress / stepProgress;
progress = progress * stepProgress;
appCompatSeekBarValorCartao.setProgress(progress);
appCompatSeekBarValorHiddenCartao.setProgress(progress);
int seekBarAtual = progress;
mapValores.put(idSeekBarValorHiddenCartao, seekBarAtual);
appCompatSeekBar.setProgress(UIUtil.somaMap(mapValores));
textViewValorLimiteCartao.setText(UIUtil.stringToCurrency(String.valueOf(contaDTO.getValorLimiteAtual().intValue() + seekBarAtual)));
textViewValorLimite.setText(UIUtil.stringToCurrency(String.valueOf(contaDTO.getValorLimiteAtual().intValue() + UIUtil.somaMap(mapValores))));
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
prevTextViewId = curTextViewId;
i++;
}