You will also handle some events.
like every time a user clicks a button, you collect the text of your edit text.
For your need there is a function:
String String.trim();
it removes all spaces that are before and after your text (leading and trailing spaces)
to use it do the following:
String msg = editText.getText().toString(); msg = msg.trim(); if(msg.equals("")){ msg = "-"; }
now "msg" will have a "hyphen" if the user has not added anything.
it's almost what @Laurence said ..
source share