setText textview with radiobutton
-
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textView = (TextView) findViewById(R.id.textView); radioGroup= (RadioGroup) findViewById(R.id.radiogroup); radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){ @Override public void onCheckedChanged(RadioGroup group, int checkedId) { // checkedId is the RadioButton selected RadioButton radioButton_250=(RadioButton)findViewById(checkedId); textView.setText(radioButton_250.getText()); RadioButton radioButton_500=(RadioButton)findViewById(checkedId); textView.setText(radioButton_500.setText("70")); } }); }
The first button that pulls the text is fine, and here's the second.
textView.setText(radioButton_500.setText("70"));
Can't let you fix this fast?
-
Stroke
textView.setText(radioButton_500.setText("70));
Not to be compiled, as the setText() method requires String as an argument and the result of the challenge.
radioButton_500.setText("70")
returnsvoid
♪If you need to change the text to the radioButton and then appoint it somewhere, do it in turn:
radioButton_500.setText("70"); textView.setText(radioButton_500.getText());
For changing the radioButtom test in RadioGroup, you have to do something like this:
radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener(){ @Override public void onCheckedChanged(RadioGroup group, int checkedId) { // checkedId is the RadioButton selected //RadioButton radioButton = (RadioButton) group.findViewById(checkedId); //textView.setText(radioButton.getText()); switch(checkedId) { case R.id.someID: //тут нужный текст установите break; case R.id.anotherID: //тут нужный текст установите break; } } });