0
私のアプリでは、TableView Dynamicalyを作成します。 ここでは、andriodのDynamicalyのようなXMLビューがあります。Android:tableView Dynamicalyを作成するには、以下のXMLコードのように?
XMLビュー:
<TableRow android:weightSum="1">
<TextView android:gravity="left"
android:textStyle="bold" android:textSize="15sp" android:textColor="#EDA700"
android:layout_marginTop="3dp" android:layout_marginBottom="8dp"
android:text="PAYE calculations: Tax period 01 April 2011 to 31 March 2012" android:layout_weight="1"/>
</TableRow>
<View android:layout_height="2dip" android:background="#FF000000" />
<TableRow android:weightSum="1">
<TextView android:gravity="center"
android:textStyle="bold" android:textSize="16sp" android:textColor="#000000"
android:layout_marginTop="3dp" android:layout_marginBottom="3dp"
android:text="All employees: Total PAYE to withhold" android:layout_weight="1"/>
</TableRow>
<!-- taxcode value -->
<!-- =================== -->
<TableRow android:weightSum="1" android:layout_marginRight="5dp">
<TextView android:gravity="left"
android:textSize="13sp" android:textColor="#000000"
android:layout_marginTop="3dp" android:layout_marginBottom="3dp"
android:text="Total gross income (salary/wages)" android:layout_weight="1"/>
<TextView android:gravity="center"
android:textSize="13sp" android:singleLine="true"
android:layout_marginLeft="5dp" android:layout_marginRight="5dp"
android:layout_marginTop="3dp" android:layout_marginBottom="3dp"
android:textColor="#000000" android:layout_weight="1"/>
<TextView android:id="@+id/taxcodeTextView" android:gravity="center" android:textColor="#000000"
android:textSize="13sp" android:singleLine="true"
android:layout_marginTop="3dp" android:layout_marginBottom="3dp"
android:layout_marginLeft="5dp" android:layout_marginRight="5dp"
android:text="00" />
</TableRow>
<!-- KiwiSaver employee Deduction percentage-->
<!-- ====================================== -->
<TableRow android:weightSum="1" android:layout_marginRight="5dp">
<TextView android:gravity="left"
android:textSize="13sp" android:textColor="#000000"
android:layout_marginTop="3dp" android:layout_marginBottom="3dp"
android:text="Total PAYE (including earner's levy)" android:layout_weight="1"/>
<TextView android:gravity="center"
android:textSize="13sp" android:singleLine="true" android:textStyle="bold"
android:layout_marginLeft="5dp" android:layout_marginRight="5dp"
android:layout_marginTop="3dp" android:layout_marginBottom="3dp"
android:text="minus" android:textColor="#000000" android:layout_weight="1"/>
<TextView
android:id="@+id/kiwiSaverEmployeeDeductionPercentageTextView"
android:gravity="center" android:textColor="#000000"
android:textSize="13sp" android:singleLine="true"
android:layout_marginTop="3dp" android:layout_marginBottom="3dp"
android:layout_marginLeft="5dp" android:layout_marginRight="5dp"
android:text="0.0%"/>
</TableRow>
</TableLayout>
私はコードの下などdynamicalyビューを作成しました:
List<TextView> textListWord = new ArrayList<TextView>(c2.getCount());
List<TextView> textListAnswer = new ArrayList<TextView>(c2.getCount());
List<ImageView> imageListAnswer = new ArrayList<ImageView>(c2.getCount());
//for(int i = 0; i < c.getCount(); i++)
c2.moveToFirst();
do
{
RelativeLayout innerLayout = new RelativeLayout(this);
innerLayout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
innerLayout.setBackgroundColor(0x00000000);
// set the Multiple TextView
TextView qWordTV = new TextView(getApplicationContext());
TextView aWordTV = new TextView(getApplicationContext());
ImageView aImageView = new ImageView(getApplicationContext());
qWordTV.setText("\n"+c2.getString(3).toString());
qWordTV.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
qWordTV.setTextColor(0xFFFF0000);
//qWordTV.layout(22, 0, 0, 0);
qWordTV.setPadding(22, 0, 0, 0);
aWordTV.setText("\n"+c2.getString(2).toString());
aWordTV.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
aWordTV.setGravity(Gravity.CENTER);
aWordTV.setTextColor(0xFFFF0000);
if(c2.getString(2).equals(c2.getString(3)))
{
aImageView.setImageResource(R.drawable.correct);
}
else
{
aImageView.setImageResource(R.drawable.incorrect);
}
aImageView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
aImageView.setPadding(400, 25, 0, 0);
/**** Any other text view setup code ****/
innerLayout.addView(qWordTV);
innerLayout.addView(aWordTV);
innerLayout.addView(aImageView);
myLinearLayout.addView(innerLayout);
textListWord.add(qWordTV);
textListAnswer.add(aWordTV);
imageListAnswer.add(aImageView);
//c.moveToNext();
}
while (c2.moveToNext());
これは、ループの条件に従ってビューdynamicalyを作成します。
ダイナミックなJavaコードに、以下のXMLレイアウトを作成して作成します。
ありがとうございました。