Android:Not able to write on textview of main activity when comming from different activity -


i created simple demo program in there start button.when click on start button on main (home) screen "hi all" appended text view.it works fine, when change activity selecting action bar menu , if again come on home screen selecting action bar home menu not show "hi " message when click on start button.

package com.example.testdemo; import android.app.actionbar.layoutparams; import android.content.intent; import android.os.bundle; import android.app.actionbar; import android.app.activity; import android.text.method.scrollingmovementmethod;     import android.view.gravity;     import android.view.menu;     import android.view.menuitem;     import android.view.view;     import android.widget.button;     import android.widget.linearlayout;     import android.widget.textview; public class mainactivity extends activity {     private textview logarea; private textview log;      @override       protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);             setcontentview(r.layout.home);             actionbar actionbar = getactionbar();             log = new textview(mainactivity.this);              log.append("heollosdfsjdf" + "\n");             @suppresswarnings("deprecation")             linearlayout.layoutparams params = new linearlayout.layoutparams(layoutparams.fill_parent,layoutparams.fill_parent);             params.gravity = gravity.left;             log.setlayoutparams(params);             log.setgravity(gravity.center);             linearlayout chat = (linearlayout) findviewbyid(r.id.main_linear_view);             log.setmovementmethod(new scrollingmovementmethod());             chat.addview(log);              setdefault();     }     public void setdefault(){             button btn = (button) findviewbyid(r.id.start_recording_button);                     btn.setonclicklistener(new view.onclicklistener() {                             @override                             public void onclick(view v) {                             startwriting(v);             }             });          }        public boolean oncreateoptionsmenu(menu menu) {             // inflate menu; adds items action bar if present.             getmenuinflater().inflate(r.menu.main, menu);             return true;     }            public boolean onoptionsitemselected(menuitem item) {             switch (item.getitemid()) {                                                                  case r.id.home:                             gohome();                             return true;                                                                     case r.id.general_setting:                             generalsetting();                             return true;                             case r.id.server_settings:                             serversetting();                             return true;                             case r.id.audio_settings:                             audiosetting();                             return true;                             default:                             break;             }             return true;     }            private void gohome() {             intent = new intent(mainactivity.this, home.class);             startactivity(i);                finish();     }     private void generalsetting() {             intent = new intent(mainactivity.this, general.class);             startactivity(i);             finish();     }      private void audiosetting() {             intent = new intent(mainactivity.this, audio.class);             startactivity(i);             finish();     }     private void serversetting() {             intent = new intent(mainactivity.this, server.class);             startactivity(i);             finish();     }        public void startwriting(view view) {              logmessage("hi all");     }     private void logmessage(string msg) {             log.append(msg + "\n");             final int scrollamount = log.getlayout().getlinetop(log.getlinecount())- log.getheight();             if (scrollamount > 0)                             log.scrollto(0, scrollamount);             else                             log.scrollto(0, 0);     }     } 

it's because called 'finish' when changed activities. calling main activity again reloads view initial state.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -