java - How to replace a null value with a string with an EditText? -


i have app edittext , when click button sends value second screen/activity. there hint in edittext upon opening app, count not null value? have if statement isn't working replace null value "friend". how can change code display "friend" when nothing typed edittext?

public class secondactivity extends activity {  public static final string tag = secondactivity.class.getsimplename();  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.secondscreen);      intent intent = getintent();     string message = intent.getstringextra("message");     if (message == null) {         message = "friend";     }     log.d(tag, message);       textview textview = (textview) findviewbyid(r.id.button);     textview.append(message);   }  @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.menu_second, menu);     return true; }  @override public boolean onoptionsitemselected(menuitem item) {     // handle action bar item clicks here. action bar     // automatically handle clicks on home/up button, long     // specify parent activity in androidmanifest.xml.     int id = item.getitemid();      //noinspection simplifiableifstatement     if (id == r.id.action_settings) {         return true;     }      return super.onoptionsitemselected(item); } 

}

welcome stackoverflow!

the method gettext() returns content of textview charsequence may empty not null. can check if it's empty calling mytextview.gettext().length == 0.

if textvew empty or filled hint, char sequence empty. second activity gets empty string never null. check rather empty string null.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -