实现TableLayout布局下循环取出TableRow控件中的文字内容到list集合

布局方式为TableLayout,利于实现表单样式展现。

<!-- 详情内容区域 -->
    <ScrollView
        android:layout_above="@id/id_buttom_layout"
        android:layout_below="@id/home_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="vertical"
        >

        <TableLayout
            android:id="@+id/id_logTableRow"
            style="@style/table"
            android:layout_marginBottom="10dip"
            android:showDividers="middle">

            <TableRow
                style="@style/tablelayout"
                 >

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingLeft="10dip"
                    android:gravity="right"
                    android:text="工单编号:"
                    android:textSize="@dimen/normal_text_size"
                    />
                 <TextView
                    android:id="@+id/id_docNumber"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingLeft="10dip"
                    android:paddingRight="10dip"
                    android:gravity="left"
                    android:textSize="@dimen/normal_text_size"
                    android:textColor="@color/balck"
                    />
            </TableRow>

            <TableRow
                style="@style/tablelayout" >
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingLeft="10dip"
                    android:gravity="right"
                    android:text="处  理  人:"
                    android:textSize="@dimen/normal_text_size"
                    />
                <TextView
                    android:id="@+id/id_logSolver"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingLeft="10dip"
                    android:paddingRight="10dip"
                    android:gravity="left"
                    android:textSize="@dimen/normal_text_size"
                    android:textColor="@color/balck"
                    />
            </TableRow>

            <TableRow
                style="@style/tablelayout" >
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingLeft="10dip"
                    android:gravity="right"
                    android:text="项目名称:"
                    android:textSize="@dimen/normal_text_size"
                    />
                <com.hxzk.ydbg.utils.views.SpinnerView
                    android:id="@+id/id_projectName"
                    android:layout_width="match_parent"
                    android:layout_height="42dp"
                    android:background="@drawable/edittext_bg_drawable"
                    android:layout_gravity="center_vertical"
                    android:textSize="@dimen/normal_text_size"
                    android:gravity="center"
                    />
            </TableRow>

            <TableRow
                style="@style/tablelayout" >
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingLeft="10dip"
                    android:gravity="right"
                    android:text="负  责  人:"
                    android:textSize="@dimen/normal_text_size"
                    />
                <TextView
                    android:id="@+id/id_projectLeader"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingLeft="10dip"
                    android:paddingRight="10dip"
                    android:gravity="left"
                    android:textSize="@dimen/normal_text_size"
                    android:textColor="@color/balck"
                    />
            </TableRow>

            <TableRow
                style="@style/tablelayout"
                 >

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingLeft="10dip"
                    android:gravity="right"
                    android:text="客户地址:"
                    android:textSize="@dimen/normal_text_size"
                    />
                 <TextView
                    android:id="@+id/id_projectAddress"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingLeft="10dip"
                    android:paddingRight="10dip"
                    android:gravity="left"
                    android:textSize="@dimen/normal_text_size"
                    android:textColor="@color/balck"
                    />
            </TableRow>

            <TableRow
                style="@style/tablelayout" >
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingLeft="10dip"
                    android:gravity="right"
                    android:text="需求类型:"
                    android:textSize="@dimen/normal_text_size"
                    />
                <com.hxzk.ydbg.utils.views.SpinnerView
                    android:id="@+id/id_logType"
                    android:layout_width="match_parent"
                    android:layout_height="42dp"
                    android:background="@drawable/edittext_bg_drawable"
                    android:layout_gravity="center_vertical"
                    android:textSize="@dimen/normal_text_size"
                    android:gravity="center"
                    />
            </TableRow>

            <TableRow
                style="@style/tablelayout">
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingLeft="10dip"
                    android:gravity="right"
                    android:text="需求描述:"
                    android:textSize="@dimen/normal_text_size"
                    />
                <EditText
                    android:id="@+id/id_logDepict"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="请填写需求的简单描述"
                    android:textSize="18sp"
                    android:inputType="textMultiLine"
                    android:minLines="3"
                    android:maxLines="100"
                    android:gravity="top"
                       android:background="@drawable/edittext_bg_drawable"
                    />
            </TableRow>

            <TableRow
                style="@style/tablelayout" >
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingLeft="10dip"
                    android:gravity="right"
                    android:text="处理结果:"
                    android:textSize="@dimen/normal_text_size"
                    />

                <EditText
                    android:id="@+id/id_logResult"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="请填写需求的处理结果"
                    android:textSize="18sp"
                    android:inputType="textMultiLine"
                    android:minLines="5"
                    android:maxLines="100"
                    android:gravity="top"
                       android:background="@drawable/edittext_bg_drawable"
                    />
            </TableRow>

            <TableRow
                style="@style/tablelayout" >
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingLeft="10dip"
                    android:gravity="right"
                    android:text="创建时间:"
                    android:textSize="@dimen/normal_text_size"
                    />
                <TextView
                    android:id="@+id/id_logCreateTime"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingLeft="10dip"
                    android:paddingRight="10dip"
                    android:gravity="left"
                    android:textSize="@dimen/normal_text_size"
                    android:textColor="@color/balck"
                    />
            </TableRow>

            <TableRow
                style="@style/tablelayout" >
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingLeft="10dip"
                    android:gravity="right"
                    android:text="处理时间:"
                    android:textSize="@dimen/normal_text_size"
                    />
                <TextView
                    android:id="@+id/id_logSolveTime"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingLeft="10dip"
                    android:paddingRight="10dip"
                    android:gravity="left"
                    android:textSize="@dimen/normal_text_size"
                    android:textColor="@color/balck"
                    />
            </TableRow>

            <TableRow
                style="@style/tablelayout" >
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingLeft="10dip"
                    android:gravity="right"
                    android:text="客户签字 \n时         间:"
                    android:textSize="@dimen/normal_text_size"
                    />
                <TextView
                    android:id="@+id/id_signTime"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:paddingLeft="10dip"
                    android:paddingRight="10dip"
                    android:gravity="left"
                    android:textSize="@dimen/normal_text_size"
                    android:textColor="@color/balck"
                    />
            </TableRow>

        </TableLayout>
    </ScrollView>

tablelayout

在Java代码中通过getChildCount、getChildAt获取tablelayout布局下的tablerow,然后再通过getChildCount、getChildAt获取tablerow下的子控件,最后通过instanceof校验对象类型并调用对应的方法获取文本。

/**表单区域*/
private TableLayout id_logTableRow;

private ArrayList<String> titleList;

初始化:

id_logTableRow = (TableLayout) initview.findViewById(R.id.id_logTableRow);
titleList = new ArrayList<String>();
        TableRow[] childs = new TableRow[id_logTableRow.getChildCount()];
        for(int i=0;i<childs.length;i++){
            childs[i] = (TableRow) id_logTableRow.getChildAt(i);
            View[] childss = new View[childs[i].getChildCount()];
            childss[0] = childs[i].getChildAt(0);
            childss[1] = childs[i].getChildAt(1);

            String labelStr = ((TextView)childss[0]).getText().toString();//每一行的左侧标签
            String infoStr = "";
            /**
             * 校验对象类型,然后再进行强类型转换,以便获取控件中的文本*/
            if(childss[1] instanceof TextView){
                infoStr = ((TextView)childss[1]).getText().toString();//每一行的左侧标签
            }else if(childss[1] instanceof SpinnerView){
                infoStr = ((SpinnerView)childss[1]).getText().toString();//每一行的左侧标签
            }
            else if(childss[1] instanceof EditText){
                infoStr = ((EditText)childss[1]).getText().toString();//每一行的左侧标签
            }else{
                infoStr = " ";
            }

            titleList.add(labelStr + infoStr);
        }
        

打印结果:

for(int i=0;i<titleList.size();i++){
            Log.v("WriteLogInfoWordFragment", (i+1) + ":" + titleList.get(i));
        }

时间: 2024-08-28 11:37:31

实现TableLayout布局下循环取出TableRow控件中的文字内容到list集合的相关文章

在Image控件中绘制文字

//Canvas 在Image控件中绘制文字 procedure TForm1.Button1Click(Sender: TObject);begin  image1.Canvas.Font.Size:= 72; //设置文字大小  image1.Canvas.TextOut(1,1,'Delphi'); //输出文字end; 来自为知笔记(Wiz) 在Image控件中绘制文字

android如何改变editText控件中部分文字的格式

我们在使用editText控件的时候,会遇到这样的一问题,就是我在输入时候,当我选择让文字变粗时,我输入的文字就会变粗,当我去掉选择时,再输入文字时,文字就是正常情况了. 这种情况,大家一般认为很简单啊.editText中不是有setTypeface这个方法吗.只要使用edit_temp.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));就可以了.可是问题来了.这种方法,是将editText中所有的文字的格式全变了.可是我想要的格式是

循环遍历listview 控件中Subitems 值

I was wanting to be able to iterate through each of my ListViews sub items and get the value from each. I have tried various things but am finding it really difficult to just get the sub item text from the second column, not the items text from the f

Android 设置子控件的宽度或高度为 match_parent来填充父控件中的剩余宽度或高度的方法

先上几张效果图, 如下:          上述四张图要实现的布局效果是: 假如父控件中包含两个子控件, 其中一个子控件(上图中为红色button)的宽度是固定数值, 而另一个子控件(上图中为绿色button)的宽度不固定, 要想让这两个子控件的总宽度刚好等于父控件的宽度.可以将宽度不固定的那个控件的宽度设置为match_parent来实现, 但有些细节需要注意, 否则即使设置了match_parent, 也不能出现如上的效果. 注意细节如下: 上述效果可以使用RelativeLayout实现.

如何写一套下拉刷新的控件?《MJRefresh原理浅析》(附Demo下载地址)

相信大家有很多人在做项目的时候都在使用MJRefresh 控件来实现下拉刷新的功能: MJRefresh经过不断的重构与更新迭代,现在不管是功能上还是代码结构上都是相当不错的,都是很值我们去学习的. 下面就是MJRefresh开源框架中中主要的一些类文件 MJRefresh主要的类文件 MJRefresh 的使用相信都难不倒大家 今天我主要想和大家分享一下MJRefresh的想法,因为我觉得这才是最重要的,献丑了,有理解的不对和不深入的地方,请大家多多点评哈! 试想,如果没有MJRefresh开

Android学习笔记--design包下的两个控件

今天学习了design包下的两个控件,记录一下,首先需要我们依赖 1 compile 'com.android.support:design:25.0.0' 之后在XML文件中就可以使用了 1 <?xml version="1.0" encoding="utf-8"?> 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 x

Delphi下使用Oracle Access控件组下TOraSession控件链接

Delphi下使用Oracle Access控件组下TOraSession控件链接数据库,使用  orsn1.Options.Direct:=true;  orsn1.Server:=IP:Port:SID;  orsn1.Username:=UserName;  orsn1.Password:=PassWord;  orsn1.Connect; 即可链接成功,这是使用SID方式链接的.但如果登陆数据库使用服务名方式,程序死活链接不上,原因,说是因为Delphi ODAC与Oracle RACD

MFC Unicode编码下,获取CString描述的IP地址并赋值到CIPAddressCtrl控件中

1. UniCode编码下,CString中字符被声明为宽字,应使用如下方法获取char* CString cstrIp = strIp; // Unicode 下将 CString转为char* int n = cstrIp.GetLength(); int len = WideCharToMultiByte(CP_ACP,0,cstrIp,cstrIp.GetLength(),NULL,0,NULL,NULL); char *p = new char[len+1]; WideCharToMu

Atitit.ui控件---下拉菜单选择控件的实现select html

Atitit.ui控件---下拉菜单选择控件的实现select   html 1. 调用& model的实现 1 2. -----select.jsp------ 1 1. 调用& model的实现 Proj.vod2 <% List li=new ArrayList(); Map m=new HashMap (); m.put("lab","爱情"); m.put("v","1"); li.add(m)