Android List Below Toggle Buttons -


i have list intended below toggle buttons. list grabs data server , parses them. xml follows:

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:orientation="horizontal" >      <togglebutton         android:id="@+id/toggle_button1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_weight="1"         android:textoff="apps"         android:texton="apps" />      <togglebutton         android:id="@+id/toggle_button2"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_torightof="@id/toggle_button1"         android:layout_weight="1"         android:textoff="vms"         android:texton="vms" />      <togglebutton         android:id="@+id/toggle_button3"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_torightof="@id/toggle_button2"         android:layout_weight="1"         android:textoff="groups"         android:texton="groups" />      <listview         android:id="@+id/mylist"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_below="@id/toggle_button1" /> </relativelayout> 

code actual fragment:

public class problemfragment extends sherlocklistfragment {     private separatedlistadapter list;      public void oncreate(bundle savedinstancestate)     {         super.oncreate(savedinstancestate);         this.getsherlockactivity().setcontentview(r.layout.problem_layout);          list = new separatedlistadapter(this.getsherlockactivity(), new layout(r.layout.separated_list_adapter_two_text, r.id.two_text_title, r.id.two_text_desc));         togglebutton b1 = (togglebutton) this.getsherlockactivity().findviewbyid(r.id.toggle_button1);         togglebutton b2 = (togglebutton) this.getsherlockactivity().findviewbyid(r.id.toggle_button2);         togglebutton b3 = (togglebutton) this.getsherlockactivity().findviewbyid(r.id.toggle_button3);          setlistadapter(list);         refresh();     }      public void refresh()     {         list = new separatedlistadapter(this.getsherlockactivity(), new layout(r.layout.separated_list_adapter_two_text, r.id.two_text_title, r.id.two_text_desc));         refreshstats();     }      public void refreshstats()     {         //omitted parsing code          list.addsection(new string("hello world!!"));         setlistadapter(list);     } } 

however, when use setlistadapter(list), buttons overwritten. visible before app retrieves data , parses it, overwritten after call setlistadapter. how can fix this?

first, remove

 android:orientation="horizontal" 

from root layout. relativelayout doesn't have orientation property. also, weight child elements of linearlayout , when use should assign width of each child view 0dp horizontal orientation , height="0dp" vertical orientation.

then wrap togglebuttons in linearlayout, vertical or horizontal orientation, , give property

android:layout_alignparenttop="true" 

then give listview property

android:layout_below="@id/idoflinearlayout" 

so may like

    <?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent" >     <linearlayout          android:id="@+id/togglell"          android:layout_width="match_parent"          android:layout_height="wrap_content"          android:layout_alignparenttop="true">     <togglebutton         android:id="@+id/toggle_button1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:textoff="apps"         android:texton="apps" />      <togglebutton         android:id="@+id/toggle_button2"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:textoff="vms"         android:texton="vms" />      <togglebutton         android:id="@+id/toggle_button3"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:textoff="groups"         android:texton="groups" />     </linearlayout>     <listview         android:id="@+id/mylist"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_below="@id/togglell" /> </relativelayout> 

i removed relativelayout properties togglebuttons since wrapped in linearlayout. , had circular view error there assigning second togglebutton right of may have been copy/paste error. hope helps.

note default orientation linearlayout horizontal leaving property out give effect.


Comments

Popular posts from this blog

Issues changing the value of an element in an array in matlab -

vb.net - Alternative to the T-SQL AS keyword -

php - MySQLi binding parameters in a prepared statement doesn't work unless inserted after "WHERE" -