Reputation: 177
I'm implementing a simple reservation system for an Android devices. I need to have one activity containing table with 7 days of week and hours from 7am to 8pm and I would like to be able to add some text to each of cells. My draft looks like this:
My problem is that I used Table Layout to do this and it caused the situation, where my layout code looks like that:
<!--7:00-->
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_column="0"
android:layout_marginBottom="1dp"
android:layout_marginRight="1dp"
android:layout_marginTop="1dp"
android:width="40sp"
android:text="\n7:00"
android:textSize="18sp" />
<TextView
android:id="@+id/textview_1_1"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_column="1"
android:textAlignment="center" />
<TextView
android:id="@+id/textview_2_1"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_column="2"
android:textAlignment="center"/>
<TextView
android:id="@+id/textview_3_1"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_column="3"
android:textAlignment="center"/>
<TextView
android:id="@+id/textview_4_1"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_column="4"
android:textAlignment="center"/>
<TextView
android:id="@+id/textview_5_1"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_column="5"
android:textAlignment="center"/>
<TextView
android:id="@+id/textview_6_1"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_column="6"
android:textAlignment="center"/>
<TextView
android:id="@+id/textview_7_1"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:layout_column="7"
android:textAlignment="center"/>
</TableRow>
As you see, to use any of those TextViews I would have to implement textview_1_1, textview_1_2 and so on. I am sure that there must be more elegant way to do this. Could some of you help me out? Thanks a lot!
Upvotes: 0
Views: 20
Reputation: 140
the best practice for this kind of problems is to use a listview with custom items(in this case edittext items) for implementing that see this or just look up 'listview custom items'
then through your listview object you can access each item (getItem()) and containing information (in your case value of edittext > gettext())
Upvotes: 1