I want to build:
Functions:
- The TableLayout should be hidden unless user checks "Include Drinks?", [DONE].
- Checking "Include Drinks?" also checks Pepsi and sets its quantity to 1. [DONE].
- Checking any Drink will set its quantity to 1, unchecking will set to 0. [?]
Unchecking "Include Drinks?" unchecks all and sets quantity to 0. [?]
In the long run i want this to be dynamically generated from an XML which might be downloaded from a server.
Right now i have coded it statically inside XML Layout(code provided below) and i know its ugly. In the OnCheckedChangeListener against checkBox_Drinks i have do a lot of code e.g. write code to uncheck everybox and set its quantity to zero. I am looking for suggestion here on how to do it in a better way.
I was doing this statically just as a PoC, i might drop the idea and jump directly to a download XML.
I was thinking to use a 3 dimensional array storing things like Drink_Name, Drink_checkBox_Name, Drink_editText_Name, and then just doing foreach kindda loop if Include Drinks checkbox was unchecked.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="5px"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<CheckBox
android:text="Include Drinks?"
android:id="@+id/checkBox_Drinks"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</CheckBox>
<!-- Pepsi -->
<TableLayout
android:id="@+id/tableLayout_Drinks"
android:layout_below="@+id/checkBox_Drinks"
android:layout_alignParentLeft="true"
android:layout_marginLeft="40px"
android:visibility="gone"
android:shrinkColumns="0,1"
android:stretchColumns="0,1"
android:layout_gravity="left"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableRow
android:id="@+id/tableRow_DrinksPepsi"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<CheckBox
android:text="Pepsi"
android:id="@+id/checkBox_DrinksPepsi"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</CheckBox>
<EditText
android:id="@+id/editText_PepsiQuantity"
android:text="0"
android:maxLength="3"
android:singleLine="true"
android:inputType="number"
android:layout_width="50px"
android:layout_height="wrap_content">
</EditText>
</TableRow>
<TableRow
android:id="@+id/tableRow_DrinksCoke"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- Coke -->
<CheckBox
android:text="Coke"
android:id="@+id/checkBox_DrinksCoke"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</CheckBox>
<EditText
android:id="@+id/editText_CokeQuantity"
android:text="0"
android:maxLength="3"
android:singleLine="true"
android:inputType="number"
android:layout_width="50px"
android:layout_height="wrap_content">
</EditText>
</TableRow>
<TableRow
android:id="@+id/tableRow_DrinksSprite"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- Sprite -->
<CheckBox
android:text="Sprite"
android:id="@+id/checkBox_DrinksSprite"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</CheckBox>
<EditText
android:id="@+id/editText_SpriteQuantity"
android:text="0"
android:maxLength="3"
android:singleLine="true"
android:inputType="number"
android:layout_width="50px"
android:layout_height="wrap_content">
</EditText>
</TableRow>
<TableRow
android:id="@+id/tableRow_Drinks7up"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- 7up -->
<CheckBox
android:text="7up"
android:id="@+id/checkBox_Drinks7up"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</CheckBox>
<EditText
android:id="@+id/editText_7upQuantity"
android:text="0"
android:maxLength="3"
android:singleLine="true"
android:inputType="number"
android:layout_width="50px"
android:layout_height="wrap_content">
</EditText>
</TableRow>
<TableRow
android:id="@+id/tableRow_DrinksMirinda"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- Mirinda -->
<CheckBox
android:text="Mirinda"
android:id="@+id/checkBox_DrinksMirinda"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</CheckBox>
<EditText
android:id="@+id/editText_MirindaQuantity"
android:text="0"
android:maxLength="3"
android:singleLine="true"
android:inputType="number"
android:layout_width="50px"
android:layout_height="wrap_content">
</EditText>
</TableRow>
<TableRow
android:id="@+id/tableRow_DrinksMoutainDew"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- MountainDew -->
<CheckBox
android:text="MountainDew"
android:id="@+id/checkBox_DrinksMountainDew"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</CheckBox>
<EditText
android:id="@+id/editText_MountainDewQuantity"
android:text="0"
android:maxLength="3"
android:singleLine="true"
android:inputType="number"
android:layout_width="50px"
android:layout_height="wrap_content">
</EditText>
</TableRow>
</TableLayout>
<Button
android:id="@+id/button_Next"
android:text="Next >"
android:textStyle="bold"
android:onClick="gotoMember"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Button>
</RelativeLayout>