Home>

I want to use a variable called id in onCreate in the SaveButtonClick method. Is there any way?

  @Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate (savedInstanceState);
        setContentView (R.layout.Mainactivity);
        final Switch mSwitch = (Switch) findViewById (R.id.switch1);
        // Listener when the state of mSwitch changes
        mSwitch.setOnCheckedChangeListener (new CompoundButton.OnCheckedChangeListener () {
            @Override
            public void onCheckedChanged (CompoundButton buttonView, boolean isChecked) {
                if (mSwitch.isChecked ()) {
                    long id = 1;
                } else {
                    long id = 0;
                }
            }
        });
}
  public void SaveButtonClick (MenuItem item) {
                DbAccess.insert (db, id);
    }