0

Please have a look at the following image

enter image description here

I am creating these checkboxes dynamically using the following code

scrollView = (ScrollView)findViewById(R.id.scrollView);
    internalTableLayout = new TableLayout(this);

    for(int i=0;i<20;i++)
    {
        CheckBox c = new CheckBox(this);
        c.setText("Word "+i);

        TableRow r = new TableRow(this);
        r.addView(c);

        internalTableLayout.addView(r);
    }

    scrollView.addView(internalTableLayout);

However, I need these checkboxes to appear in right hand side. So, you know when it is right hand side, the "text" of the checkbox comes first, then the checkbox comes.

How can I do that?

halfer
  • 19,824
  • 17
  • 99
  • 186
PeakGen
  • 21,894
  • 86
  • 261
  • 463
  • Please refer to my answer to do it in a better way: [How to show android checkbox at right side?][1] [1]: http://stackoverflow.com/questions/3156781/how-to-show-android-checkbox-at-right-side/21991349#21991349 – Hazhir Feb 24 '14 at 15:05

3 Answers3

6

If you want to use the CheckBox widget and achieve the same then you can do something like this.

android:button="@null"
android:drawableRight="?android:attr/listChoiceIndicatorMultiple"
sundar.siva
  • 61
  • 1
  • 2
  • This! Thank you very much. For those who are looking for a list of those default attributes, they are defined in /res/values/attrs.xml of your SDK platform installation. – Dan Tumaykin Jan 28 '15 at 13:29
3

Use a CheckedTextView which already has what you want http://developer.android.com/reference/android/widget/CheckedTextView.html

EDIT: This is a dup of: How to show android checkbox at right side? and How to Set the Checkbox on the right side of the text So check those links if you need other ways to solve it, but the elegant way is to do CheckedTextView

Community
  • 1
  • 1
Vrashabh Irde
  • 14,129
  • 6
  • 51
  • 103
1

You could do what Slartibartfast suggested or create a checkbox with a label of "" and add a separate TextView to the left if that doesn't suit your fancy.

loeschg
  • 29,961
  • 26
  • 97
  • 150