android - show the text of an EditText into a TextView -


describing functionality of application: have put in relative layout textview, edittext , button. trying is: when user writes in edittext , push button, content of edittext appeared in textview(just chat-virtual chat). works perfectly, when edittext empty,and button pushed, empty line appeared in textview(and don't want to..). although i've tried solve using if empty line still appearing in textview. greatfull, if help!!! in advance!

here code:

package teiath.android.appliacation;  import android.app.activity;  import android.os.bundle; import android.text.method.scrollingmovementmethod; import android.view.view; import android.widget.button; import android.widget.edittext; import android.widget.textview;  public class m_chat extends activity {     /** called when activity first created. */     @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);          /**code scroll bars in textview. */         final textview tv = (textview)findviewbyid(r.id.text_view);         tv.setmovementmethod(new scrollingmovementmethod());//for scroll bars          /** code scroll bars in edittext. */         final edittext wr = (edittext)findviewbyid(r.id.edit_text);         wr.setmovementmethod(new scrollingmovementmethod());//for scroll bars          final button button = (button) findviewbyid(r.id.btn1);//find button id in main.xml         button.setonclicklistener(new view.onclicklistener() {             public void onclick(view v) {                 // perform action on click                   string wrcontent = wr.gettext().tostring();//gets text of edittext , put in "tvcontent" variable.                  string tvcontent = tv.gettext().tostring();//gets text of textview , put in "tvcontent" variable.                    if (wrcontent!="")//if edittext not empty                 {                     //check if textview empty or not                     if (tvcontent!="")//if not empty...                      {                         tv.settext(tvcontent + "\n" + wrcontent);//add current(textview's text) text, new line , text of edittext new text of textview.                         //tv.setvisibility(0);//makes visible textview cloud1.png background                         wr.settext("");//set text of edit text empty                         //wrcontent = "";                     }                     else//if textview empty...                     {                         tv.settext(wrcontent);//add text of edittext new text of textview                         wr.settext("");                     }                 }                 /**if (wrcontent=="")                 {                  }*/                 //finish();             }         });       } } 

don't use !="" string comparison. check empty text, use like

if ( wrcontent != null && wrcontent.trim().length() == 0 ) { 

better yet, include guava libraries in code.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

c# - SharpSVN - How to get the previous revision? -

php cli reading files and how to fix it? -