Android 如何获取所有editText的文本?

Android 如何获取所有editText的文本?,android,android-edittext,Android,Android Edittext,如何获取所有editText的文本 我需要对所有的文本进行循环 我有16个编辑文本,在循环中需要轮流获取所有文本 我正在努力 TableLayout or = (TableLayout) findViewById(R.id.TableLayoutBells); EditText editTextBells = (EditText) or.getChildAt(i).findViewById(R.id.TableLayoutBells); 但它不起作用 这是我的布局: <?xml ver

如何获取所有editText的文本

我需要对所有的文本进行循环

我有16个编辑文本,在循环中需要轮流获取所有文本

我正在努力

TableLayout or = (TableLayout) findViewById(R.id.TableLayoutBells); 
EditText editTextBells = (EditText) or.getChildAt(i).findViewById(R.id.TableLayoutBells);
但它不起作用

这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/RelativeLayoutScheduleOfBellsEdit"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/back1"
        android:visibility="visible"
        tools:context=".MainActivity" >

        <ImageView
            android:id="@+id/imageViewTopScheduleOfBellsEdit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/top_schedule_of_bells" />

        <ScrollView
            android:id="@+id/scrollView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/imageViewTopScheduleOfBellsEdit" 
            android:layout_above="@+id/LinearLayoutOkCancelScheduleOfBellsEdit">

                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:orientation="vertical" >

                                <TableLayout
                                    android:id="@+id/TableLayoutBells"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:layout_marginTop="10dp"
                                    android:background="@drawable/grid_view_notes_background" >

                                    <TableRow
                                        android:id="@+id/tableRow1"
                                        android:layout_width="wrap_content"
                                        android:layout_height="wrap_content"
                                        android:layout_marginLeft="10dp" >

                                        <TextView
                                            android:id="@+id/TextView03"
                                            android:layout_width="wrap_content"
                                            android:layout_height="wrap_content"
                                            android:layout_weight="2"
                                            android:text="1st lesson:"
                                            android:textAppearance="?android:attr/textAppearanceLarge" />

                                        <EditText
                                            android:id="@+id/EditText1"
                                            android:layout_width="0dp"
                                            android:layout_height="wrap_content"
                                            android:layout_weight="50"
                                            android:background="@drawable/edittext_edit_text_holo_light"
                                            android:ems="10"
                                            android:inputType="time"
                                            android:maxLength="5"
                                            android:tag="0" >

                                            <requestFocus />
                                        </EditText>

                                        <LinearLayout
                                            android:layout_width="wrap_content"
                                            android:layout_height="wrap_content"
                                            android:layout_weight="1"
                                            android:orientation="vertical" >

                                            <TextView
                                                android:id="@+id/TextView01"
                                                android:layout_width="wrap_content"
                                                android:layout_height="wrap_content"
                                                android:layout_gravity="left"
                                                android:text="—"
                                                android:textAppearance="?android:attr/textAppearanceLarge" />
                                        </LinearLayout>

                                        <EditText
                                            android:id="@+id/EditText01"
                                            android:layout_width="0dp"
                                            android:layout_height="wrap_content"
                                            android:layout_weight="50"
                                            android:background="@drawable/edittext_edit_text_holo_light"
                                            android:ems="10"
                                            android:inputType="time"
                                            android:maxLength="5"
                                            android:tag="1" />

                                    </TableRow>

                                    ...
                                </TableLayout>

                            </LinearLayout>
                        </ScrollView>

        <LinearLayout
                android:id="@+id/LinearLayoutOkCancelScheduleOfBellsEdit"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:orientation="horizontal" >

                <ImageView
                    android:id="@+id/imageViewCancelScheduleOfBellsEdit"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/cancel_click" />

                <ImageView
                    android:id="@+id/imageViewOkScheduleOfBellsEdit"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="10dp"
                    android:layout_marginLeft="10dp" 
                    android:src="@drawable/ok_click" />

            </LinearLayout>

    </RelativeLayout>

...
也类似于:

首先,如果只需要循环编辑文本,可以将每个视图id添加到数组列表中,如下所示:

ArrayList<EditText> list = new ArrayList<EditTexts>();
EditText edit = (EditText) view.findViewById(R.id.X);
list.add(edit);
-或者,如果您需要使用您定义的表格布局,那么您是否尝试删除最后一行的findViewById结尾

TableLayout or = (TableLayout) findViewById(R.id.TableLayoutBells); 
EditText editTextBells = (EditText) or.getChildAt(i);

这对我来说很有效,这是布朗诺问题。快乐编码
TableLayout or = (TableLayout) findViewById(R.id.TableLayoutBells); 
EditText editTextBells = (EditText) or.getChildAt(i);