Reputation: 11
I have created a function which allows the user to enter text in EditText and then when the user clicks the send button it displays it on the screen in textView, but I want to remove the text from edittext once the user clicks on the send button and I only want it to display on the textview and nowhere else, how can I accomplish this?
private void addMessage() {
final EditText myMessageField = (EditText) findViewById(R.id.messageField);
final TextView displayText = (TextView) findViewById(R.id.printMessage);
Button btnSendMessage = (Button) findViewById(R.id.btnSend);
btnSendMessage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
displayText.setTextSize(TypedValue.COMPLEX_UNIT_SP,22);
displayText.setText(myMessageField.getText().toString());
}
});
}
Upvotes: 1
Views: 2966
Reputation: 4651
in the onClick
add this.
myMessageField.setText("");
it'll make the edittext text to blank
so it'll be like this:
btnSendMessage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
displayText.setTextSize(TypedValue.COMPLEX_UNIT_SP,22);
displayText.setText(myMessageField.getText().toString());
//erasing text from edittext
myMessageField.setText("");
}
});
}
Upvotes: 2