0

I've recently started to build android apps, and I wanted to know if it's actually possible to make a selectable button in android like the image in the link below ?

https://lh4.ggpht.com/ouHPcTcFzsdYrTU09pStGBicxgX_cki613g5Eq3loYCh2TOXzqpfeyWnOdlLuc8eNS0=h900-rw

I'm trying to make a list of numbers that you can do multiple checks, however, I'm not sure if I must use a check box or some other widget. It would be great if I can hear some tips from the pros here!

Jennifer
  • 1,822
  • 2
  • 20
  • 45
  • Go with Ravi's answer he is right – Hanish Sharma Mar 03 '15 at 09:33
  • 1
    Just make checkbox to all and set value and when ever you want click value just check checkbox is clicked or not ... – duggu Mar 03 '15 at 09:33
  • @Ravi you know if you are using button then you must have to use click event with array so better approach is use check boxes as per my opinion. – duggu Mar 03 '15 at 09:36
  • I will try it , but I wonder if there is some helpful example or tutorial on google that can help a noob like me ? – Jennifer Mar 03 '15 at 09:56

2 Answers2

1

It really depends on what logic you want to have. Are there any logical connections between those numbers? Any conditions?

You could also use a ToggleButton: http://developer.android.com/guide/topics/ui/controls/togglebutton.html

Styling: Android toggle button custom look

Then there is the question of how many buttons do you want to have? Perhaps a variable amount? Then you could use a GridView with ToggleButtons.

Also there are possibilities to use RadioButtons, it's up to you.

Community
  • 1
  • 1
einschnaehkeee
  • 1,858
  • 2
  • 17
  • 20
  • Thank you, I want to make multiple buttons like like about 31. I want to make them selectable with clicks . But the problem is that I want a number in the middle of those buttons. – Jennifer Mar 03 '15 at 10:15
  • "About 31" sounds like a variable amount. Perhaps it's better to use a GridView with whatever component of your choice. With a `ToggleButton` you can have text centered. – einschnaehkeee Mar 03 '15 at 10:27
0

Try this sample

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@null"
        android:button="@drawable/button_change_view"/>

    <CheckBox
        android:id="@+id/checkBox2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@null"
        android:button="@drawable/button_change_view"/>

    <CheckBox
        android:id="@+id/checkBox3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@null"
        android:button="@drawable/button_change_view"/>

    <CheckBox
        android:id="@+id/checkBox4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@null"
        android:button="@drawable/button_change_view" />

    <CheckBox
        android:id="@+id/checkBox5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@null"
        android:button="@drawable/button_change_view" />
</LinearLayout>

</RelativeLayout>

button_change_view.xml is :-

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/location_hide"
      android:state_checked="true" />
<item android:drawable="@drawable/location_show"
      android:state_checked = "false" />
</selector>

Using this you don't need to maintain button state , checkbox maintain by itself.

Himanshu arora
  • 161
  • 4
  • 11
  • I'm trying to do your sample, but, if I want to make the checkbox itself like a number in the middle of the button like the image , how can I do it ? – Jennifer Mar 04 '15 at 11:32
  • 1
    Just use the images of numbers 1,2,3,4,5,6,... and apply these images on checkbox ,You don't need to take button ,you can do your work only with checkboxes – Himanshu arora Mar 13 '15 at 10:42