android - EditText field displaying data on different tabs -


i'm having pretty strange issues app. have edittext element, lets call display, in reused fragment each tab. every time launch app see following initial behaviour when click button sends text output display. not use system keyboard, buttons send display.

the best way think of web browser tabs, can edit url in each tab independently, , buttons, live below in other 2 sections, supply input. it's not web browser, analogy works.

enter image description here

  • don't click on -> text drawn in b tab
  • click on b -> text drawn in c tab
  • click on c -> text drawn in c tab
  • click on b -> click on c -> app crashes

i might running fencepost error i'm not sure. can text draw in a's output after click or two.

@override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.container);      midpager = (viewpager) findviewbyid(r.id.function_container);     toppager = (viewpager) findviewbyid(r.id.top_container);     midpageradapter = new midpageadapter(getfragmentmanager());     midpager.setadapter(midpageradapter);      final actionbar actionbar = getactionbar();     actionbar.setnavigationmode(actionbar.navigation_mode_tabs);     actionbar.setdisplayoptions(0, actionbar.display_show_title);      tabsadapter toptabsadapter = new tabsadapter(this,toppager);     toptabsadapter.addtab(actionbar.newtab().settext("1"),                            topfragment.class, null);     toptabsadapter.addtab(actionbar.newtab().settext("2"),                            topfragment.class, null);     toptabsadapter.addtab(actionbar.newtab().settext("3"),                            topfragment.class, null);      if (savedinstancestate != null) {         actionbar.setselectednavigationitem(savedinstancestate.getint("tab",0));     } } 

and in function manages tabs have:

public static class tabsadapter extends fragmentpageradapter implements actionbar.tablistener, viewpager.onpagechangelistener {     private final context mcontext;     private final actionbar mactionbar;     private final viewpager mviewpager;     private final arraylist<tabinfo> mtabs = new arraylist<tabinfo>();      static final class tabinfo {         private final class<?> clss;         private final bundle args;          tabinfo(class<?> _class, bundle _args) {             clss = _class;             args = _args;         }     }      public tabsadapter(activity activity, viewpager pager) {         super(activity.getfragmentmanager());         mcontext = activity;         mactionbar = activity.getactionbar();         mviewpager = pager;         mviewpager.setadapter(this);         mviewpager.setonpagechangelistener(this);     }      public void addtab(actionbar.tab tab, class<?> clss, bundle args) {         tabinfo info = new tabinfo(clss, args);         tab.settag(info);         tab.settablistener(this);         mtabs.add(info);         mactionbar.addtab(tab);         notifydatasetchanged();     }      @override     public int getcount() {         return mtabs.size();     }      @override     public fragment getitem(int position) {         tabinfo info = mtabs.get(position);         return fragment.instantiate(mcontext, info.clss.getname(), info.args);     }      @override     public void onpagescrolled(int position, float positionoffset,                                int positionoffsetpixels) {     }      @override     public void onpageselected(int position) {         mactionbar.setselectednavigationitem(position);     }      @override     public void ontabselected(tab tab, fragmenttransaction ft) {         object tag = tab.gettag();          (int = 0; < mtabs.size(); i++)         {             if (mtabs.get(i) == tag)             {                 setactivemap(i);                 mviewpager.setcurrentitem(i);             }         }     } } 

in reusable fragment have oncreate function.

@override public view oncreateview(layoutinflater inflater, viewgroup container,                          bundle savedinstancestate) {     view v = inflater.inflate(r.layout.top_fragment, container, false);     foobar active = container.getactivemap();     active.editline = (edittext) v.findviewbyid(r.id.display);     active.editline.setcursorvisible(false);     active.editline.addtextchangedlistener((textwatcher) this);     ((edittext) v.findviewbyid(r.id.display)).setonclicklistener(this);     return v; } 

one question me debug how can debug edittext within reused fragment in tabs? data edittext widget use distinguish tab tab? i've tried various .tostring()'s of functions without success.

the more ideal solution simple error spot in code. help.

we have 3 separate fragments of same configuration seems unnecessarily ugly.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -