title: Button has to be clicked twice in Android Studio to work (different from other peoples issues)
body: <p>I have 2 edit texts and both of them are linked to their respective image buttons. When I click the buttons and use the input from edit text it only works once I press it for the second time. Basically I have a big value and any number I put in the edit text is subtracted from the big value once the button is pressed.</p>
  
  <p>I have another button on the same activity that takes you to the settings activity but that one works perfectly fine, I do not know why these 2 buttons require double tap.</p>
  
  <p><strong>XML Code:</strong></p>
  
  <pre><code>  &lt;ImageButton
      android:id="@+id/plusCal"
      android:layout_width="38dp"
      android:layout_height="32dp"
      android:layout_marginStart="120dp"
      android:layout_marginBottom="124dp"
      android:background="@color/white"
      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintStart_toStartOf="parent"
      app:srcCompat="@drawable/plus" /&gt;
  </code></pre>
  
  <p><strong>Activity Code:</strong></p>
  
  <p>public class MainActivity extends AppCompatActivity {</p>
  
  <pre><code>//create private ImageButton Object
  private ImageButton setting_button;
  TextView Cremaining, Premaining;
  EditText MinusCal, MinusPro;
  ImageButton plusCal, plusPro;
  
  String calData, proData;
  SharedPreferences prefs;
  
  int calint, proint, Calinput, ProInput;
  String Result;
  
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      prefs = PreferenceManager.getDefaultSharedPreferences(this);
      calData = prefs.getString("Cal_Total","0");
      proData = prefs.getString("Pro_Total","0");
  
  
      //retrieve TxtView using findviewbyID
      Cremaining = (TextView) findViewById(R.id.RemainingCal);
      Premaining = (TextView) findViewById(R.id.RemainingPro);
  
      //Retrieve EditButton using findviewbyID
  
      MinusCal = (EditText)findViewById(R.id.EditCal) ;
      MinusPro = (EditText)findViewById(R.id.EditPro);
  
      //Retrieve Button using findViewbyID
      plusCal = (ImageButton)findViewById(R.id.plusCal);
      plusPro = (ImageButton)findViewById(R.id.plusProtein);
  
  
  
      //Set Protein and Calories either from settings or update from result
          Cremaining.setText(calData);
          Premaining.setText(proData);
  
      plusCal.setOnClickListener(new View.OnClickListener(){
          @Override
          public void onClick(View v) {
  
              SharedPreferences.Editor editor = prefs.edit();
  
              //Subtract Calories from Input calories, then set total to calData and save and set text
              Calinput = Integer.parseInt(MinusCal.getText().toString());
              calint = Integer.parseInt(calData);
              calint -= Calinput;
              calData = String.valueOf(calint);
              editor.putString("Cal_Total", calData);
              calData = prefs.getString("Cal_Total","0");
              Cremaining.setText(calData);
  
  
  
  
              editor.apply();
  
          }
                                     });
  </code></pre>
  
  <p>Ignore the formatting and redundant variables, I aim to clean up the code once I have the issue working, same goes with any error handling (try catches)</p>
  
  <p>UPDATE: I figured it out:
  The editor, I am using .apply() instead of commit and I am using it late in the call of execution, so i set  the value, save it to shared preferences, and then recall the shared preferences without commiting in the right flow which causes it too pick up the old value. </p>