-1

I am naive to Android development. I believe Android Studio is super cool and made life easier but there is something I am stuck with for hours.

I want to make a UI element exactly like shown below. It will contain a person name and check box.
enter image description here

I want to select people and I want in this way.


Please can anyone tell me how to construct this UI element and how to use these elements horizontaly in list view ?

Mahammad Adil Azeem
  • 9,112
  • 13
  • 57
  • 84

4 Answers4

2

Try these attributes in your checkbox object to have the text on left and the checkbox on right:

android:button="@null"
android:drawableRight="?android:attr/listChoiceIndicatorMultiple"
muratgu
  • 7,241
  • 3
  • 24
  • 26
  • @AdilMalik if you need to play with padding (and who knows what else), you are better of creating a custom layout with a textbox and a checkbox. – muratgu Jun 29 '16 at 19:09
  • No Custom Layout is more complex. I solved it putting 2 spaces before name (which looks like padding from left side :P) – Mahammad Adil Azeem Jun 29 '16 at 19:12
1

You can try something like this

<CheckBox
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="person_name"
  android:background="@drawable/stroke.xml"
  android:checked="false" />

stroke.xml in your drawable

<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#606060"/>
<stroke android:color="#303030" android:width="2dp" />
</shape>

Make this as a layout of your listView

To make a Listview with multiple Checkboxes

  1. Make a ArrayList of Data you want in your listView
  2. Make a CustomAdapter using BaseAdapter
  3. Pass the ArrayList to the Adapter
  4. Now set your Checkboxes content to the values in your Arraylist like arraylist.get(postion).names

You can checkout this sample code on implementation of Listview with Checkboxes.

Siddhesh Dighe
  • 2,894
  • 3
  • 16
  • 16
  • 1
    Yes, I know how to make things work with list adapter. But I don't know how to make listView horizontal – Mahammad Adil Azeem Jun 29 '16 at 19:02
  • 1
    Another thing is that i am confused about that how can i add padding from stroke background ? – Mahammad Adil Azeem Jun 29 '16 at 19:02
  • 1
    If you want a Grid like layout, i would suggest moving on to the `RecyclerView` as it handles the orientation with `LayoutManagers`. And adding padding to your checkbox element with background as a stroke would work just fine according to me – Siddhesh Dighe Jun 29 '16 at 19:08
  • 1
    @AdilMalik check this out http://stackoverflow.com/questions/3240331/horizontal-listview-in-android it may help – Siddhesh Dighe Jun 29 '16 at 19:09
1

This will give the same as you expected.

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

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="David cooper"/>

    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView1"
        android:layout_alignParentRight="true"
        android:layout_marginRight="15dp"/>
</RelativeLayout>
Mr.7
  • 2,292
  • 1
  • 20
  • 33
0

You likely want a LinearLayout, orientation horizontal, containing a TextView and a CheckBox

https://developer.android.com/training/basics/firstapp/building-ui.html

Will probably a lot of help

draksia
  • 2,371
  • 2
  • 20
  • 25