Android的:如何创建的tableView Dynamicaly像下面的xml code? [英] Android: How to create the tableView Dynamicaly as like below xml code?

查看:108
本文介绍了Android的:如何创建的tableView Dynamicaly像下面的xml code?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我想创建的TableView Dynamicaly:
在这里,我有XML视图像我想要什么Dynamicaly在Andriod的。

In My app i want to create the TableView Dynamicaly: Here i have xml view as like what i want Dynamicaly in andriod.

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视图,如下面code:

I have created dynamicaly view as like below code:

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创建视图按循环的状态。

This will create the view dynamicaly as per the condition of the loop.

我想下面的XML布局中dynamicaly的java code创建它。

I want the below xml layout in to dynamicaly java code to create it.

感谢。

推荐答案

喜来看看这个链接它应该有你想要的!
HTTP://wowjava.word$p$ pss.com/2011/04/01/dynamic-tablelayout-in-android/

Hi take a look at this link it should have what you want!!! http://wowjava.wordpress.com/2011/04/01/dynamic-tablelayout-in-android/

这篇关于Android的:如何创建的tableView Dynamicaly像下面的xml code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆