我有2個輻射羣。第一個有4個按鈕,第二個有3個按鈕。 我需要一個解決方案來更新TextView中的計時器,具體取決於兩個radiogroup中檢查的內容。在第一個radiogroup用戶選擇大小,第二個用戶選擇形狀。這給了12個組合。到目前爲止,我只想到如何更新1個radiogroup中的TextView字段。在下面的代碼中,我已經顯示了來自第一個radiogroup(rg1)的2個值。他們應該根據在radiogroup 2(rg2)中選擇的內容進行更改在Android中合併2個輻射羣
我找到了解決方案並更新了代碼。希望它能幫助別人。
public class MainActivity extends Activity implements RadioGroup.OnCheckedChangeListener {
TextView timer;
RadioGroup rg1;
RadioGroup rg2;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
timer = (TextView) findViewById(R.id.softTimer);
rg1 = (RadioGroup) findViewById(R.id.myRadioGroup1);
rg1.setOnCheckedChangeListener(this);
rg2 = (RadioGroup) findViewById(R.id.myRadioGroup2);
rg2.setOnCheckedChangeListener(this);
}
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
RadioButton s1 = (RadioButton) findViewById(R.id.size_small);
RadioButton s2 = (RadioButton) findViewById(R.id.size_medium);
RadioButton s3 = (RadioButton) findViewById(R.id.size_large);
RadioButton s4 = (RadioButton) findViewById(R.id.size_xlarge);
RadioButton b1 = (RadioButton) findViewById(R.id.boil_soft);
RadioButton b2 = (RadioButton) findViewById(R.id.boil_medium);
RadioButton b3 = (RadioButton) findViewById(R.id.boil_hard);
if (s1.isChecked() && b1.isChecked()){
tid = 204000;
eggTimer.setText("00:03:24");
}
else if (s1.isChecked() && b2.isChecked()) {
tid = 255000;
eggTimer.setText("00:04:15");
}
else if (s1.isChecked() && b3.isChecked()) {
tid = 341000;
eggTimer.setText("00:05:41");
}
else if (s2.isChecked() && b1.isChecked()){
tid = 239000;
eggTimer.setText("00:03:59");
}
else if (s2.isChecked() && b2.isChecked()) {
tid = 279000;
eggTimer.setText("00:04:39");
}
else if (s2.isChecked() && b3.isChecked()) {
tid = 396000;
eggTimer.setText("00:06:36");
}
else if (s3.isChecked() && b1.isChecked()){
tid = 270000;
eggTimer.setText("00:04:30");
}
else if (s3.isChecked() && b2.isChecked()) {
tid = 325000;
eggTimer.setText("00:05:25");
}
else if (s3.isChecked() && b3.isChecked()) {
tid = 485000;
eggTimer.setText("00:08:05");
}
else if (s4.isChecked() && b1.isChecked()){
tid = 336000;
eggTimer.setText("00:05:36");
}
else if (s4.isChecked() && b2.isChecked()) {
tid = 400000;
eggTimer.setText("00:06:40");
}
else if (s4.isChecked() && b3.isChecked()) {
tid = 603000;
eggTimer.setText("00:10:03");
}
final CounterClass timer = new CounterClass(tid, 1000);
tv_start_egg1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
timer.start();
}
});
tv_stop_egg1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
timer.cancel();
tid = 0;
eggTimer.setText("00:00:00");
}
});
}
}
請張貼您的解答作爲答案並接受它。這樣問題將被列爲答案。謝謝。 – David
因此,我應該用舊的替換代碼,發佈新的解決方案,然後將其設置爲答案?對不起,但我是這個網站的新手:-) –
無需更改問題代碼。我認爲任何人都不會從錯誤的代碼中受益。重點是,如果任何人看到你的「在Android中組合2個無線電組」問題,他們應該找到答案。將其置於公認的答案中的唯一原因是其他人可以看到它已被回答。 – David