is it possible to update the text in edittext when it’s already set? i’ve filled up my edittext with the name and phone number of a person from my listview, and i want the user to edit these details. when i tried to enter for example a surname and click the update button, it cannot save my input and still saved the one that i passed coming from my listview.
EditText sqlName = (EditText)findViewById(R.id.editName);
EditText sqlNumber = (EditText)findViewById(R.id.editNumber);
name = CustomListView.name;
num = CustomListView.number;
Button bUpdate = (Button)findViewById(R.id.editUpdate);
Button bView = (Button)findViewById(R.id.editView);
sqlName.setText(name);
sqlNumber.setText(num);
nameChanged = sqlName.getText().toString();
numChanged = sqlNumber.getText().toString();
bUpdate.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
GroupDb info = new GroupDb(EditDetails.this);
info.open();
long rowid = info.getRowId(name, num);
Toast.makeText(getApplicationContext(), nameChanged+" "+numChanged+" ", Toast.LENGTH_LONG).show();
info.updateNameNumber(rowid, nameChanged, numChanged);
Toast.makeText(getApplicationContext(), "Update Successful!", Toast.LENGTH_LONG).show();
info.close();
}
});
The problem with your code is that you are fetching the values from the EditTexts even before they were updated. You need to wait for the user to press the update button and then get the text from the EditTexts and pass them to the database to save.
Try the following code.