How can I check if he clicked again?

2

I'm doing a program for Android with access to database. Then I have an edit button, which when I pulse I deactivate a create button. To modify a text.

Then I want that when I click again on the edit button (which at this moment has text on the button, "Save"). Well, do a series of things, my problem is that I do not know that I have to put a condition in the if to know if you have pressed the button when its value is Save.

I copy what is related to the edit button, the if how can you see I have it empty. Have if someone can give me a hand in what I have to put in the condition. Thank you very much in advance.

private Button btnEditar;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

btnEditar = (Button) findViewById(R.id.btnEditar);

btnEditar.setOnClickListener(this);

}


public void onClick(View v) {
 switch (v.getId()) {

  case R.id.btnEditar:
   // Si hay alguna receta seleccionada permitimos su modificación
  if(c!=null){
   editReceta.setText(txtReceta.getText());
   btnCrear.setEnabled(false);
   btnEditar.setText("Guardar");

  if(...){                    db.actualizar(c.getId(),editNombre.getText().toString(),editReceta.getText().toString());
        btnCrear.setEnabled(true);
        btnEditar.setText("Editar");
     }  
   }
    break;
}
    
asked by Antonio 30.11.2018 в 18:16
source

1 answer

0

Define a variable in the class:

private int haGuardadoDosOcasiones = 0;

when doing the save increment the variable, when done twice the value of haGuardado would be 2:

haGuardado++;

Now in your if you can define that you perform the update if you have "saved" twice, you can also restart the variable by doing what is indicated in the code block:

 if(haGuardado > 1){                    
 db.actualizar(c.getId(),editNombre.getText().toString(),editReceta.getText().toString());
        btnCrear.setEnabled(true);
        btnEditar.setText("Editar");

       //reinicia variable
       haGuardado = 0;
}
    
answered by 30.11.2018 в 18:22