I have an Activity
with 34 Switch
, and loading the activity is fine.
However, when I try to replace the Switch
with CheckBox
the activity takes a full second to load.
Is this a general problem with CheckBox
or is my code just not appropriate?
My code for the activity, simplified (shows only 1 CheckBox
)
public class Myactivity extends AppCompatActivity {
CheckBox MyCheckbox1;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_myactivity);
MyCheckbox1 = findViewById(R.id.mycheck1);
Mycheckbox1.OnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
onCheckedChanged(CompoundButton view, boolean isChecked) {
if(((CompoundButton) view).isChecked()){
//do something
}else{
//do something else
}
}
}
}
}
My XML code for the Checkboxes:
<CheckBox
android:id="@+id/mycheck1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Option1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Aucun commentaire:
Enregistrer un commentaire