1

I want to create the following pseudo layout in android and I'd like some help to determine the best approach:

enter image description here

The months of the year will all be listed in buttons and when the user clicks on them an action will occur. The day of the month gets stored to storage if you need to know. The size of the circles are all the same and their behavior is identical, just their name is different (and they each store their own name of course). What is the best UI approach I can take in android to do this? I thought of a few things:

  1. obvious create 12 buttons for each day of the month and have onclicks that read there text and store it.
  2. create a custom button and programatically add 12 buttons to a linearLayout in code.
  3. could I somehow use a plural in android to get this done ?
Roland Illig
  • 40,703
  • 10
  • 88
  • 121
j2emanue
  • 60,549
  • 65
  • 286
  • 456

1 Answers1

2

Android plurals is for handling strings with numbers, which doesn't seem to apply to your situation.

For large quantities of UI elements you may wish to use styles to cut down on duplication of code. Also any future changes you make that are part of the style will only have to be done once, instead of twelve times. Here is an example button style FYI:

<resources

   <style name="GroovyButtons">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:layout_alignParentLeft">true</item>
        <item name="android:textAllCaps">false</item>
        <item name="android:textSize">13sp</item>
        <item name="android:textColor">@color/text_color</item>
        <item name="android:background">@drawable/button_custom</item>
    </style>

</resources>

Save this code into styles.xml, which is inside values directory in the res folder. Then in each button you reference the button style:

style="@style/GroovyButtons"

Any attributes that you repeat in the XML layout will override what you have in the style. Overriding attributes in your styles is of course completely optional.

joshgoldeneagle
  • 4,616
  • 2
  • 23
  • 30
  • Hey thanks. I already know about styles. The questions are more about how to handle the buttons. Like should I create a custom view b that had 10 buttons built-in or 10 separate buttons or one custom one and forloop the rest programmatically. Plus one for the plural comment – j2emanue Aug 10 '15 at 23:02
  • Not sure which way is better... Did you see this info on dynamically creating buttons? http://stackoverflow.com/questions/1851633/how-to-add-a-button-dynamically-in-android – joshgoldeneagle Aug 10 '15 at 23:11