Change Text in dynamically added Row
iam realy new in Android and got some question:
I have some TableLayout, in this i want to add some rows dynamically. The
rows have to look the same, so i wrote a template in xml and add this as
view to the row.
In this xml file, there are some TextViews, and now i want to change the
Text of these TextViews in every TableRow, so that every table row got
some other text, like Sunday, Monday etc.
Later i want to add this Text from an array.
The TableLayoute xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/SPone_RL1"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/backrepeat"
android:layout_gravity="center_vertical">
<ImageView
android:id="@+id/SPone_RL_ImageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@drawable/logo"
android:layout_centerInParent="true"
/>
<ScrollView
android:id="@+id/SPone_RL_SV"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="@+id/SPone_RL_SV_RL"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TableLayout android:id="@+id/SPoneTable"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:padding="10dip" android:stretchColumns="*">
</TableLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
The Row xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/SPone_RL_SV_RL_RL"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:id="@+id/SPone_RL_SV_RL_RL_LL1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
>
<LinearLayout
android:layout_width="30dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="20dp">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="12"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/white"
android:textSize="25sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="20dp">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="Sonntag"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/white"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/SPone_RL_SV_RL_RL_LL2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/SPone_RL_SV_RL_RL_LL1" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="70dp" >
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="25.08.2013"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/white"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="20dp" >
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="15:00"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/white"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/SPone_RL_SV_RL_RL_LL3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/SPone_RL_SV_RL_RL_LL2"
>
<TextView
android:id="@+id/textView5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="FC Bergalingen - FC Binzgen I"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/white"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/SPone_RL_SV_RL_RL_LL4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/SPone_RL_SV_RL_RL_LL3"
>
<TextView
android:id="@+id/textView6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="0:6"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/white"
android:textSize="30sp" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
The Java Code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fcbonespielplan);
/* Find Tablelayout defined in main.xml */
TableLayout tl = (TableLayout) findViewById(R.id.SPoneTable);
for(int i = 0; i < 10; i++) {
/* Create a new row to be added. */
TableRow tr = new TableRow(this);
tr.setLayoutParams(new
TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.WRAP_CONTENT));
/* Create a View to be the row-content. */
LayoutInflater layoutInflater = (LayoutInflater)
this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//das Layout das 10 mal rein soll
ViewGroup yourview =
(ViewGroup)layoutInflater.inflate(R.layout.spielplantablerow,
null);
/* Add View to row. */
tr.addView(yourview);
/* Add row to TableLayout. */
tr.setBackgroundResource(R.drawable.baggroundtable);
tl.addView(tr, new
TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT,
TableLayout.LayoutParams.WRAP_CONTENT));
}
}
Can anybody help me how i can set every time an other text to, maybe one
of the TextViews? Without generate the whole TextView from the Java?
No comments:
Post a Comment