/** {@inheritDoc} */ private void updateChecked() { if (menu == null) return; ((CompoundButton) menu.findItem(R.id.toggleView).getActionView().findViewById(android.R.id.toggle)) .setChecked(model.isChecked()); }
/** {@inheritDoc} */ @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); inflater.inflate(R.menu.actionbar_toggle_menu, menu); // Binds the button CompoundButton cBox = (CompoundButton) menu.findItem(R.id.toggleView).getActionView().findViewById(android.R.id.toggle); cBox.setOnCheckedChangeListener( new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton cb, boolean checked) { model.setChecked(checked); } }); // Set label text ((TextView) menu.findItem(R.id.toggleView).getActionView().findViewById(android.R.id.text1)) .setText(getArguments().getString(ARG_LABEL_TEXT)); this.menu = menu; updateChecked(); }