Hi,
I am trying to learn the basics of android with Java and got struck halfway creating a simple app.
This checkbox code works for single text and can someone help me make one text visible and hide second one.
I am trying to learn the basics of android with Java and got struck halfway creating a simple app.
This checkbox code works for single text and can someone help me make one text visible and hide second one.
Code:
import ...
public class MainActivity extends AppCompatActivity {
private TextView txtHelloWorld;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CheckBox checkBoxVisibility = findViewById(R.id.checkBox_visibility);
txtHelloWorld = findViewById(R.id.txtHelloWorld);
boolean isChecked = checkBoxVisibility.isChecked();
updateTextVisibility(isChecked);
checkBoxVisibility.setOnClickListener(v -> {
boolean isChecked1 = ((CheckBox)v).isChecked();
updateTextVisibility(isChecked1);
});
}
private void updateTextVisibility(boolean isChecked) {
if (isChecked) {
txtHelloWorld.setVisibility(View.VISIBLE);
} else {
txtHelloWorld.setVisibility(View.INVISIBLE);
}
}
}