android - Why doesn't my Fragment's layout change dynamically? -


i making fragment layout supposed change dynamically. here it's layout:

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical"      android:id="@+id/root">  </linearlayout>   

in oncreateview(), listview or gridview added programatically based on orientation. however, on configuration change, nothing happens. here how handle configuration change:

    @override     public void onconfigurationchanged(configuration newconfig){          if(newconfig.orientation == configuration.orientation_portrait){             root = (linearlayout) getactivity().findviewbyid(r.id.root);             root.removeallviewsinlayout();             listview = new listview(getactivity());             listview.setadapter(adapter);             root.addview(listview,params);         }else if(newconfig.orientation == configuration.orientation_landscape){             root = (linearlayout) getactivity().findviewbyid(r.id.root);             root.removeallviewsinlayout();             gridview = new gridview(getactivity());             gridview.setnumcolumns(2);             gridview.setcolumnwidth(150);             gridview.setadapter(adapter);             root.addview(gridview,params);         }     }   

i tried removing views on configuration change nothing happens. what needs changed here?

have "registered" activity configchanges?

you need add:

 <activity android:name="com.bla.bla.youractivity"             android:configchanges="keyboardhidden|orientation|screensize" > 

in manifest in order calls onconfigurationchanged...

edit:

however, better way use 2 different layouts in different layout folders (layout-land or layout-port). 1 gridview , other 1 listview. way don't need handle config change "manually". handle differences in oncreate... (your activity destroyed , created again on config change...)


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -