我有3个微调器。我正在使用计时器自动显示微调器的内容。
当我运行应用程序时。纺纱厂的内容同时进行。
现在我想在选择spinner1然后spinner2被激活(运行)时使旋转器运行,当选择spinner2然后激活spinner3(运行)
这是我的代码......
public void addListenerOnButton() {
spinner1 = (Spinner) findViewById(R.id.spinner1);
spinner2 = (Spinner) findViewById(R.id.spinner2);
spinner3 = (Spinner) findViewById(R.id.spinner3);
btn_choose1 = (Button) findViewById(R.id.button1);
btn_choose2 = (Button) findViewById(R.id.button2);
btn_choose3 = (Button) findViewById(R.id.button3);
timer1 = new Timer();
timer1.schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
if(spinner1.getSelectedItemPosition() == (Arrays.asList(getResources().getStringArray(R.array.cincin_warna)).size()-1)){
spinner1.setSelection(0);
}else{
spinner1.setSelection(spinner1.getSelectedItemPosition()+1);
}
}
});
}
},0,1000);
btn_choose1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(timer1!=null){
timer1.cancel();
}
}
});
timer2 = new Timer();
timer2.schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
if(spinner2.getSelectedItemPosition() == (Arrays.asList(getResources().getStringArray(R.array.cincin_warna)).size()-1)){
spinner2.setSelection(0);
}else{
spinner2.setSelection(spinner2.getSelectedItemPosition()+1);
}
}
});
}
},0,1000);
btn_choose2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(timer2!=null){
timer2.cancel();
}
}
});
timer3 = new Timer();
timer3.schedule(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
if(spinner3.getSelectedItemPosition() == (Arrays.asList(getResources().getStringArray(R.array.cincin_warna)).size()-1)){
spinner3.setSelection(0);
}else{
spinner3.setSelection(spinner3.getSelectedItemPosition()+1);
}
}
});
}
},0,1000);
btn_choose3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(timer3!=null){
timer3.cancel();
}
}
});