Reputation: 71
The method below is responsible for inserting a new record to a database table and it is called when a button
is pressed. However the String input that is assigned the value of the contents of the EditText
never seems to be assigned to the new contents whenever a new value is typed in.
As a result inserting a new record only works once.
Any suggestions why this happens would be appreciated.
public void insertRecord(View additionBut) {
System.out.println("NOW INSIDE THE INSERT RECORD");
input = addTextInput.getText().toString();
addTextInput.getText().clear();
System.out.println(input);
if (purpose.equals("ViewNovel")) {
md.addPiece(input, "0");
} else if (purpose.equals("ViewPlay")) {
md.addPiece(input, "1");
} else {
// whatever else
}
displayList();
}
Upvotes: 0
Views: 91
Reputation: 894
Place
displayList();
addTextInput.getText().clear(); //after displayList();
May be the reference is same. Because of that when you try to clear the edit text the value in input getting reflected. If so, try creating new String object with the value in the edit text box.
Upvotes: 0
Reputation: 29662
You can also clear your EditText in another way, Try following way,
public void insertRecord(View additionBut) {
System.out.println("NOW INSIDE THE INSERT RECORD");
input = addTextInput.getText().toString();
addTextInput.setText("") // Change here
System.out.println(input);
if (purpose.equals("ViewNovel")) {
md.addPiece(input, "0");
} else if (purpose.equals("ViewPlay")) {
md.addPiece(input, "1");
} else {
// whatever else
}
displayList();
}
Upvotes: 1