моя проблема в том, что, когда установлен один флажок, он показывает текст, который он должен использовать. Но когда оба флажка отмечены, он отображает только текст второго.Строка возвращает число вместо текста?
public class MainActivity extends Activity {
TextView text;
CheckBox firstCheck, secondCheck;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
firstCheck = (CheckBox) findViewById(R.id.checkBox1);
secondCheck = (CheckBox) findViewById(R.id.checkBox2);
text = (TextView) findViewById(R.id.textView2);
}
public void buttonClick(View view) {
if(firstCheck.isChecked()) {
text.setText(R.string.checkbox_1);
}
if(secondCheck.isChecked()) {
text.setText(R.string.checkbox_2);
}
if(firstCheck.isChecked()==false && secondCheck.isChecked()==false) {
text.setText(R.string.unchecked);
}
}
}
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Les 2_1</string>
<string name="hello_world">Hello world!</string>
<string name="checkbox_1">Checkbox 1 </string>
<string name="checkbox_2">Checkbox 2</string>
<string name="button_1">Click here!</string>
<string name="textview_2">And?</string>
<string name="unchecked">No buttons checked!</string>
</resources>
хорошо, конечно, его будет, вы перезаписать текст, когда он проходит 'secondCheck' – tyczj
Рекомендуем также firstCheck.isChecked() == false избыточно, используйте! firstCheck.isChecked() – reactivemobile