コード例 #1
0
  /** {@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();
  }
コード例 #2
0
  /** {@inheritDoc} */
  @Override
  public void onResume() {
    super.onResume();

    updateChecked();
  }
コード例 #3
0
  /** {@inheritDoc} */
  @Override
  public void onAttach(Activity activity) {
    super.onAttach(activity);

    this.model = (ActionBarToggleModel) activity;
  }