1
두 번째 라디오 버튼이 끈적 거리는 것을 제외하면 라디오 버튼이 잘 작동합니다. 다른 것들은 선택되어 토글되지만, 디스플레이는 두 번째 버튼이 고정되어 있음을 보여줍니다.안드로이드의 끈적한 라디오 버튼
아래의 자체 코드 예제를 참조하십시오. 나는 4.0.3을 사용하고 있고 이클립스를 사용하여 에뮬레이터에서 실행 중이다.
감사
package small.example;
import android.app.Activity;
import android.os.Bundle;
import android.widget.*;
public class SmallActivity extends Activity {
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout main=new LinearLayout(this);
main.setOrientation(LinearLayout.VERTICAL);
int question=1;
button=new Button(this);
button.setText("Make a choice");
main.addView(button);
button.setId(question);
setContentView(main);
int answers=4;
radioButtons=new RadioButton[answers];
RadioGroup radioGroup=addRadioButtonsToGroup(question,radioButtons);
LinearLayout linearLayout=new LinearLayout(this);
linearLayout.addView(radioGroup);
linearLayout.setId(question);
// radioButtons[0].setChecked(true);
main.addView(linearLayout);
}
private RadioGroup addRadioButtonsToGroup(int question,RadioButton[] radioButtons) {
RadioGroup radioGroup=new RadioGroup(this);
for(int i=0;i<radioButtons.length;i++) {
radioButtons[i]=new RadioButton(this);
radioButtons[i].setText("Question "+question+" Choice "+(i+1));
radioButtons[i].setId(i);
radioGroup.addView(radioButtons[i]);
}
radioGroup.setOnCheckedChangeListener(radioGroupOnCheckedChangeListener);
radioGroup.setId(question);
return radioGroup;
}
RadioButton[] radioButtons;
Button button;
RadioGroup.OnCheckedChangeListener radioGroupOnCheckedChangeListener=new RadioGroup.OnCheckedChangeListener(){
public void onCheckedChanged(RadioGroup group,int checkedId) {
int id=checkedId;
button.setText(radioButtons[id].getText());
}
};
}
위대한! - 매력처럼 작동합니다. 덕분에 –
도와 줘서 기뻐요. 좋은 질문, 자그마한, 자체 포함 된 예제 - 잘라내어 붙여넣고 문제를보기 위해 실행하십시오. 더 많은 포스터 만이 같은 양의 문제를 해결하면. – NickT