Method to get all EditTexts in a View

android get child view of linearlayout
android get child view from parent view
how to get dynamic edittext value in android
get text from edittext android
how to set value in edittext in android
get string from edittext android
how to set text to textview in android dynamically
android:text input

can anyone help me with coding a method to get all EditTexts in a view? I would like to implement the solution htafoya posted here: How to hide soft keyboard on android after clicking outside EditText?

Unfortunately the getFields() method is missing and htafoya did not answer our request to share his getFields() method.


MByD pointed me to an error, thus making my answer almost identical to that of blackbelt. I have edited mine to the correct approach.

You could do a for-each loop and then check if each view is of the type EditText:

ArrayList<EditText> myEditTextList = new ArrayList<EditText>();

for( int i = 0; i < myLayout.getChildCount(); i++ )
  if( myLayout.getChildAt( i ) instanceof EditText )
    myEditTextList.add( (EditText) myLayout.getChildAt( i ) );

You could also, instead of having a list of EditTexts, have a list of ID's and then just add the id of the child to the list: myIdList.add( child.getId() );

To access your layout you need to get a reference for it. This means you need to provide an ID for your layout in your XML:

<LinearLayout android:id="@+id/myLinearLayout" >
   //Here is where your EditTexts would be declared

Then when you inflate the layout in your activity you just make sure to save a reference to it:

LinearLayout myLinearLayout;

public void onCreate( Bundle savedInstanceState ) {
   super( savedInstanceState );
   setContentView( R.layout.myLayoutWithEditTexts );


   myLinearLayout = (LinearLayout) findViewById( );

You then have a reference to your the holder of your EditTexts within the activity.

Can I get all EditText of an android layout at once?, Here's a method I wrote to recursively check all EditText children of a ViewGroup, handy for a long sign-up form I had to do and probably more maintainable. Continue with low Android Kotlin Get All Edittexts In View weight/high reps or increase weights and reduce rep range but not hypertrophy. Example: using machines and doing bicep curls, I will do 5 sets for 20 reps at 19kg (when I was trying to build mass I was Android Kotlin Get All Edittexts In View at 50kg on machine for 6 reps).

Here's a method I wrote to recursively check all EditText children of a ViewGroup, handy for a long sign-up form I had to do and probably more maintainable.

private EditText traverseEditTexts(ViewGroup v)
    EditText invalid = null;
    for (int i = 0; i < v.getChildCount(); i++)
        Object child = v.getChildAt(i); 
        if (child instanceof EditText)
            EditText e = (EditText)child;
            if(e.getText().length() == 0)    // Whatever logic here to determine if valid.
                return e;   // Stops at first invalid one. But you could add this to a list.
        else if(child instanceof ViewGroup)
            invalid = traverseEditTexts((ViewGroup)child);  // Recursive call.
            if(invalid != null)
    return invalid;

private boolean validateFields()
    EditText emptyText = traverseEditTexts(mainLayout);
    if(emptyText != null)
        Toast.makeText(this, "This field cannot be empty.", Toast.LENGTH_SHORT).show();
        emptyText.requestFocus();      // Scrolls view to this field.
    return emptyText == null;

android Method to get all EditTexts in a View?, can anyone help me with coding a method to get all EditTexts in a view? I would like to implement the solution htafoya posted here: How to hide soft keyboard on � Hey guys, I have a list of items that have edit texts in them. I want to save the value of each edittext to a corresponding string. However, when I try to get a hold of the edittext, by using something like a TextWatcher or FocusChangeListener, I end up getting all of the edittexts in the listview.

You can do it by calling View#getFocusables, which will return an arraylist of all focusable views in a View.

Then you can either check if they are EditTexts, with (instanceof) or act on all of them.

Method to get all EditTexts in a View, In our previous tutorials, we have seen how different types of layout are useful for In our example, we will take input from the user through EditText view and will OnClickListener() { @Override public void onClick(View v) { // clearing out all� Create an ArrayList of EditTexts, and then use a for loop to apply the TextWatcher for all EditTexts, if you have one behavior for all editTexts, then just apply it there, if you specific behaviors for some specific editTexts, then u can use an if statement to select and apply to individual editTexts … here is my code:

This Methods walks recursively through all ViewGroups and collects their TextViews. I use this to assign a new Color to all TextViews (even those embedded in predefined Widgets like Switch etc that make use of TextViews)

private HashSet<TextView> getTextViews(ViewGroup root){
    HashSet<TextView> views=new HashSet<>();
    for(int i=0;i<root.getChildCount();i++){
        View v=root.getChildAt(i);
        if(v instanceof TextView){
        }else if(v instanceof ViewGroup){
    return views;

EditText, Iterate and get name and text of all EditText in a View the for loop would be better exposed to a method, because looping through the layout� Value of edittext get change when scrolling; Edittext loses content on scroll in recyclerview. Edittext loses focus in recyclerview; This tutorial will solve all the above problems in this Android RecyclerView with EditText Example.

Get all Edit Text in any type of layout.

public List<EditText> getAllEditTexts(ViewGroup layout){
        List<EditText> views = new ArrayList<>();
        for(int i =0; i< layout.getChildCount(); i++){
            View v =layout.getChildAt(i);
            if(v instanceof EditText){
        return views;

Get Value from the EditText and Set value to the TextView, In android, we can get the text of EditText control by using getText() method in Activity file. android:textAllCaps, It is used to present the text in all CAPS In case if you are not aware of creating an app in android studio check this article� I have tried here to store the texts gotten from each of the edittexts created and storing them in an array which when the display button is clicked. When the shuffle button is clicked i tried to loop through the array and get the texts for each edittext in the array added it to an arraylist and then shuffling the list.

Iterate and get name and text of all EditText in a View — Xamarin , A simple way to get the user to enter text is to use an EditText object; you'll find it going in different directions, and you'll see all available properties: public void onSubmit(View v){ //get references to the objects in the layout Similarly I want to clearFocus of all my EditTexts and TextView (since Copy/Paste option shows up in middle of the drawer when it is open). I know I can write code for each Fragment calling onDrawerSlide function and clearing Focus for each element individually, but I want to know if it is possible for a generic solution and if so, how to do it.

Android EditText with Examples, An EditText is added to a layout with all default behaviors with the following XML: Getting the value of the text entered into an EditText is as follows: Check out the basic event listeners cliffnotes for a look at how to listen for changes to an� edittextfullname.getText().toString() : This means when the user enters the name in edittextfullname we get the entered value from this method with the help of getText() and then the value or name is converted in to string by using toString().

Getting what the user typed — Android #7, and call setupUI(findViewById(, that is all. If you want to use this effectively, you may create an extended Activity and put this method in, and make all other activities in your application extend this activity and call its setupUI() in the onCreate() method. Hope it helps.

  • Are you sure this line is a valid one: for( View child : myLayout ) ?
  • It appears I was a bit hasty in my response - as MByD says, the for-each loop is not valid for a View/Layout.
  • I am feeling like a noop right now, I cannot get your suggestion to work. I have coded several pages of android/java code so far but I am stuck here. I found out that I have to include java.util.list for the list type. But then Eclipse tells me that the new List<EditText>() is not valid... And also I am wondering if the list type is compatible with the array [] htafoya's solution is expecting. Is this the same or do I have to change this to a list too? Thanks for your help!
  • Hmm, the List problem might be my error. Try changing it to an ArrayList. If you need an array instead of the list, you simply use myList.toArray() after you're done adding/removing from the list. The advantages of the list, is that it is dynamical which means there is no need for a fixed size like with a normal array.
  • Hopefully my last question: How can I access the layout?