android - Fragment not coming null even when not in layout -


i developing 2 pane app appearance changes based on screen orientation. in portrait mode, app displays listfragment. in landscape, have both listfragment , descriptionfragment contains textview.

in portrait mode, when click on item in listview, app should show me description in activity holds descriptionfragment. on other hand, in landscape mode, description should appear in descriptionfragment in same layout.

it works fine in portrait mode, , when switch landscape. problem appears when return portrait landscape.

in following code, fragment1 id of descriptionfragment in layout. in portrait mode f null , go activity. when in landscape f not null , works. when return portrait mode, f not null textview null , app crashes.

when come portrait, why able find fragment, though not in layout?

    protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_my_list);         listview lv = (listview) findviewbyid(android.r.id.list);         final fragmentmanager fm = getsupportfragmentmanager();         lv.setonitemclicklistener(new adapterview.onitemclicklistener() {             @override             public void onitemclick(adapterview<?> adapterview, view view, int i, long l) {                 fragment f = fm.findfragmentbyid(r.id.fragment1);                 if (f == null) {                     intent p = new intent(mylistactivity.this, descriptionactivity.class);                     p.putextra("pos", i);                     startactivity(p);                 } else {                     textview tv = (textview) findviewbyid(r.id.description);                     if (tv != null)                         tv.settext(citiesdata[i]);                 }             }         });     } } 


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -