этот сайт был чрезвычайно полезен для меня, так что мне приятно возвращаться.
RE: Кевин М. (11 февраля 2012 г.) - «... что если бы у меня были переключатели x (x> 1), определяющие вид изображения»
Это работает:
Если они были у вас в группе радиостанций, то в любой момент времени будет выбран только один. Итак, ваша задача найти какой.
РЕДАКТИРОВАТЬ: код отредактирован с учетом сценария трех радиогрупп в вашем последующем комментарии
public void imgchnggrps(View v)
{
RadioButton two = (RadioButton) findViewById(R.id.two);
RadioButton three = (RadioButton) findViewById(R.id.three);
RadioButton first = (RadioButton) findViewById(R.id.first);
grp1index = 0;
if (two.isChecked()) {
grp1index = 1
} else if (three.isChecked()) {
grp1index = 2;
} else if (first.isChecked()) {
grp1index = 3;
} else { //you don't need this else, but for completion
grp1index = 0;
}
grp2index = 0;
if (two.isChecked()) {
[...]
}
grp3index = 0;
if (two.isChecked()) {
[...]
}
imgchng(grp1index, grp2index, grp3index);
}
public void imgchng(a, b, c)
String img = default_image; //this is a string form of the drawable
switch a{
case 0:
switch b{
case 0:
switch c{
case 0: img = "thisimage" // drawable resource's id
}
break;
}
break;
case 1:
(switch b and c as above)
break;
case 2:
(switch as above)
break;
}
int viewid = getResources().getIdentifier(yourimageviewid, "id", yourpackagename);
int imgid = getResources().getIdentifier(img, "drawable", yourpackagename);
ImageView thisview = (ImageView) findViewById(viewid);
thisview.setImageResource(imgid);
}
Затем в файле макета назначьте этот метод событию onclick для каждой переключательной кнопки, например так:
android: onClick = "imgchnggrps"
Надеюсь, это поможет.