Hello i am working on android studio and i have done an insert data method. It works but the text areas wont clean after succesful message is shown. This is my code
boolean isInserted = myDb.insertData(editName.getText().toString(),
editSurname.getText().toString(),
editDate.getText().toString(),
editPhone.getText().toString(),
gender.toString(),
jobValue.toString(),
txtMartese.toString(),
editBirthplace.getText().toString());
if(isInserted=true){
Refresh();
Toast.makeText(MainActivity.this, "Data Inserted",Toast.LENGTH_LONG).show();
}
else
Toast.makeText(MainActivity.this,"Data not Inserted", Toast.LENGTH_LONG).show();
}
}
And this is the Refresh(); code
public void Refresh() {
btnReset.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
editName.setText("");
editSurname.setText("");
editBirthplace.setText("");
editDate.setText("");
editPhone.setText("");
male.setChecked(false);
female.setChecked(false);
job.setChecked(false);
}
});
}
On button it works but when data is inserted nothing happens, thank you in advance.
CodePudding user response:
It doesnt work because Refresh() is a button and waits for a click what you should do is this
public void Reset(){
//Clear text area code here
}
public void Refresh() {
btnReset.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Reset();
}
});
}
boolean isInserted = myDb.insertData(editName.getText().toString(),
editSurname.getText().toString(),
editDate.getText().toString(),
editPhone.getText().toString(),
gender.toString(),
jobValue.toString(),
txtMartese.toString(),
editBirthplace.getText().toString());
if(isInserted=true){
Reset();
Toast.makeText(MainActivity.this, "Data Inserted",Toast.LENGTH_LONG).show();
}
else
Toast.makeText(MainActivity.this,"Data not Inserted", Toast.LENGTH_LONG).show();
}
}