0

How to get text of all editText?

I need to go in a cycle over all edittext.

I have 16 editText and in cycle need get text of all in turns.

i was try

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

but it dont work

this is my layout:

<?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>
Shayan Pourvatan
  • 11,898
  • 4
  • 42
  • 63

1 Answers1

0

Also similiar to: Method to get all EditTexts in a View

I would first state that if you only need to cycle over the edit texts, you can add each of their view id's to an array list like :

ArrayList<EditText> list = new ArrayList<EditTexts>();
EditText edit = (EditText) view.findViewById(R.id.X);
list.add(edit);

Then loop over them to get the text you need, like:

for (EditText edit : list){
   String text = edit.getText().toString();
}

-Or if you need to use the table layout you defined then have you tried removing the ending findViewById on your last line?

TableLayout or = (TableLayout) findViewById(R.id.TableLayoutBells); 
EditText editTextBells = (EditText) or.getChildAt(i);
Community
  • 1
  • 1
John Shelley
  • 2,655
  • 3
  • 27
  • 36