0
In meiner Anwendung füge ich RadioButton dynamisch je nach Anforderung hinzu. Unten ist der Code:Überprüfen, ob RadioButton aktiviert ist, wenn es dynamisch hinzugefügt wird?
RadioGroup rg = new RadioGroup(StartExamActivity.this);
View v = new View(StartExamActivity.this);
v.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 2));
v.setBackgroundColor(Color.parseColor("#3593D4"));
rg.setLayoutParams(new RadioGroup.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
rg.setOrientation(LinearLayout.VERTICAL);
for (int i = 0; i < list.size(); i++) {
rdbtn[i] = new RadioButton(StartExamActivity.this);
rdbtn[i].setLayoutParams(new RadioGroup.LayoutParams(RadioGroup.LayoutParams.MATCH_PARENT, RadioGroup.LayoutParams.WRAP_CONTENT, 1f));
rdbtn[i].setId(i);
rdbtn[i].setText(list.get(i));
final String value = rdbtn[i].getText().toString();
rdbtn[i].setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (value.equalsIgnoreCase(answer)) {
marks = marks + 2;
}
}
});
rg.addView(rdbtn[i]);
}
questionContainer.addView(rg);
Jetzt möchte ich den Wert von Marken erhöhen von 2 Einzigen, selbst wenn RadioButton- mehrfach überprüft. Dafür möchte ich wissen, ob RadioButton aktiviert ist oder nicht. Wie geht das?
Bitte Hilfe !!
http://stackoverflow.com/questions/11050074/how-to-check-if-radiobutton- is-checked –
Bitte beachten Sie diese [link] (http://stackoverflow.com/questions/22855276/cant-get-the-values-from-dynamicadded-check-box) und [link2] (http: // stackoverflow.com/questions/12213545/check-the-state-of-checkboxes-which-were-added-dynamically) hoffe, es wird für Sie arbeiten –