1

I have a layout where I put i rows dynamically in a tablelayout that is inside a scrollview. Everything is working smoothly except that I don't can get the checkbox text to wordwrap (See xml below). The text is also set at runtime. I have searched the internet and has made a lot of trying to set different properties with no luck so far.

Is this task possible to achieve?

<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:layout_marginBottom="15dip">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <CheckBox 
            android:id="@+id/bes_checkbox"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="" />

        <EditText
            android:id="@+id/bes_kommentar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/bes_checkbox" />

    </RelativeLayout>

</TableRow>
Orkun
  • 6,998
  • 8
  • 56
  • 103
  • He means he does't want the text content to get cut off. He wants it to automatically wrap to the next line. – Shoerob Apr 14 '14 at 13:03
  • I think if you set maxWith attribute of the checkbox to something constant like 150dp, it will wrap its text. – M D P Jul 13 '16 at 12:04

3 Answers3

2

CheckBox extends TextView, so I assume you can wrap its text like they solve the issue in this post :

If you cannot get it to work like that, you can maybe also try, using match_parent in the checkbox.

      <CheckBox 
        android:id="@+id/bes_checkbox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="" />

hope it helps.

Community
  • 1
  • 1
Orkun
  • 6,998
  • 8
  • 56
  • 103
  • 1
    I was generating `Table Layout` at RunTime and was facing the same issue with `CheckBox`. Setting its `height` to `matchParent` in `layoutParams` helped me. I had set the `width` to 0dp. It worked for me hence I upvoted. I dont think so I would have considered setting `height` to `matchParent` without going thru this post – DeltaCap019 Aug 02 '13 at 14:07
-1

use table row inside the Linear layout instead of table layout..

      android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

    <TableRow
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="15dip" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <CheckBox
                android:id="@+id/bes_checkbox"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
             />

            <EditText
                android:id="@+id/bes_kommentar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/bes_checkbox" />
        </RelativeLayout>
    </TableRow>

    <TableRow
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="15dip" >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <CheckBox
                android:id="@+id/bes_checkbox"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                />

            <EditText
                android:id="@+id/bes_kommentar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/bes_checkbox" />
        </RelativeLayout>

    </TableRow>
</LinearLayout>
Sniper
  • 2,412
  • 11
  • 44
  • 49
-1

I have made dynamic layouts with checkboxes in the past and used this approach:

// Create new view to add layout to
sv = new ScrollView(this);
// Create new layout to add check boxes to
ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
// Add layout to view
sv.addView(ll);    

// Create 6 check boxes
int itemSize = 6;
for(int j=0; j<itemSize; j++){
    CheckBox cb = new CheckBox(this);
    cb.setText("number " + j);
    ll.addView(cb);
}
// Finalize view
this.setContentView(sv);

Is this what you are looking for?

Jon
  • 3,174
  • 11
  • 39
  • 57