Note that there are some explanatory texts on larger screens.

plurals
  1. PONot sure how to dynamically add checkboxes in 2 columns
    text
    copied!<p>I am trying to display information from a database as checkboxes. Right now it works fine, but places one column of checkboxes on the screen. What I want to do is have it split into 2.</p> <p><strong>What it Does Now:</strong><br> item1<br> item2<br> item3<br> item4<br> item5</p> <p><strong>What I Want:</strong><br> item1 item2<br> item3 item4<br> item5</p> <p>Preferably the new 2 column list would be evenly sized, each getting 50% of the screen, even if the text assigned is different lengths. </p> <p>I have searched a lot, and tried like 3 different things. Havn't found anything that works. Below is my code as it is (creating one column). </p> <pre><code>private void listStudents() { st = (LinearLayout)findViewById(R.id.studTable); ml = (RelativeLayout)findViewById(R.id.main); ArrayList&lt;ArrayList&lt;String&gt;&gt; studentlst = new ArrayList&lt;ArrayList&lt;String&gt;&gt;(); studentlst = db.getAllStudentsRowsAsArrays(); final int sllen = studentlst.size(); final String student[][] = new String[sllen][3]; CheckBox cb[] = new CheckBox[sllen]; TextView pemail[] = new TextView[sllen]; int num = st.getChildCount(); if(num != 0) st.removeAllViews(); String tsl = sllen + ""; nos.setText(tsl); for(int x=0; x &lt; sllen; x++) { /************************ * student[x][case] * * case options * * 0 = id * * 1 = name * * 2 = email * ************************/ String curstudent = studentlst.get(x).toString(); student[x][0] = curstudent.substring(1,curstudent.indexOf(",")); student[x][1] = curstudent.substring(curstudent.indexOf(" ")+1,curstudent.lastIndexOf(",")); student[x][2] = curstudent.substring(curstudent.lastIndexOf(" ")+1, curstudent.length() - 1); } Arrays.sort(student, new Comparator&lt;String[]&gt;() { @Override public int compare(String[] entry1, String[] entry2) { String name1 = entry1[1]; String name2 = entry2[1]; return name1.compareTo(name2); } }); for(int x=0;x&lt;sllen;x++) { cb[x] = new CheckBox(this); cb[x].setId(x+100); cb[x].setText(student[x][1]); pemail[x] = new TextView(this); pemail[x].setText(student[x][2]); pemail[x].setId(x+1000); pemail[x].setVisibility(View.INVISIBLE); st.addView(cb[x],x); ml.addView(pemail[x],x); } } </code></pre> <p>XML File</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/main" android:layout_width="match_parent" android:layout_height="match_parent" &gt; &lt;TextView android:id="@+id/lblmainselclass" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginLeft="82dp" android:layout_marginTop="7dp" android:text="@string/lblmainselectclass" /&gt; &lt;Spinner android:id="@+id/mainclassspinner" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_toRightOf="@+id/lblmainselclass" /&gt; &lt;ScrollView android:id="@+id/scrollView1" android:layout_width="wrap_content" android:layout_height="250dp" android:layout_below="@+id/lblmainselstudents" android:layout_centerHorizontal="true" &gt; &lt;LinearLayout android:id="@+id/studTable" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" &gt; &lt;/LinearLayout&gt; &lt;/ScrollView&gt; &lt;TextView android:id="@+id/lblmainselstudents" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/mainclassspinner" android:layout_centerHorizontal="true" android:layout_marginTop="5dp" android:text="@string/lblselectstud" /&gt; &lt;Button android:id="@+id/btnsend" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:text="@string/btnlblsend" /&gt; &lt;Spinner android:id="@+id/mainresponsespinner" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/btnsend" android:layout_centerHorizontal="true" android:layout_marginBottom="30dp" /&gt; &lt;TextView android:id="@+id/mainnumofstudents" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentLeft="true" android:text="@string/invis" android:visibility="invisible" /&gt; &lt;TextView android:id="@+id/classselected" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:text="@string/invis" android:visibility="invisible" /&gt; &lt;TextView android:id="@+id/responseselected" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:text="@string/invis" android:visibility="invisible" /&gt; &lt;TextView android:id="@+id/numchecked" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:text="@string/invis" android:visibility="invisible" /&gt; </code></pre> <p></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload