layout - What is the default value of android:text of EditText while the android:text is left undefined? -


i'm beginner in android development. in project, created tablelayout --i reckon gridlayout can more help, since i'm not familiar gridlayout tablelayout taken -- edittexts values user. activity submit-able form. left of each edittext, there textview defining expected corresponding edittext, don't have , didn't set default text edittext (which used hint). there button in activity submitting form. picked edittexts must_filled ones, in button's custom listener class, have check if these must_filleds have been filled. follow intuition coded follow:

string s4 = machine_id.gettext().tostring().trim(); if(s4 == null || s4 == ""){     toast.maketext(v.getcontext(),              "please input machine id", toast.length_short).show(); } 

machine_id here android:id edittext. code ends no toast displayed. think there default text value edittext though android:text not defined manually. wrote simple project confirm thought. here mainactivity.java

public class edittext_testactivity extends activity implements view.onclicklistener{ /** called when activity first created. */ private string text;     @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);         edittext et = (edittext)findviewbyid(r.id.et01);         text = et.gettext().tostring();          button btn = (button)findviewbyid(r.id.btn01);         btn.setonclicklistener(this);     }  @override public void onclick(view v) {     if(text != null)         toast.maketext(v.getcontext(), text, toast.length_short).show();     else         toast.maketext(v.getcontext(), "null", toast.length_short).show();  } } 

and main.xml:

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:orientation="vertical" >      <edittext         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:id="@+id/et01" />     <button          android:layout_width="wrap_content"          android:layout_height="wrap_content"         android:id="@+id/btn01"         android:text="touchme"/>  </linearlayout> 

it proved edittext has default text value, because toast.maketext(v.getcontext(), text, toast.length_short).show(); show toast. however, shows looks blank space not is.

finally, i'm wondering default value of android:text in edittext.

thanks in advance.

i believe default value empty string. never null because if that's case, should have encountered nullpointerexception @ line:

string s4 = machine_id.gettext().tostring().trim(); 

looking @ code, reason why toast did not show because used (s4 == null || s4 == "") if condition. == operator different .equals(). try changing condition "".equals(s4) instead.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -