Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8688803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:28:13+00:00 2026-06-12T23:28:13+00:00

I have looked at other questions regarding this problem but the solutions don’t work

  • 0

I have looked at other questions regarding this problem but the solutions don’t work for me. I have a number of edittext fields on a page and want to be able to reset them with one button press. I implemented the solution from this thread but I have nested linear layouts and it only clears the edittext that is a direct child of the main container. How can I get it to find all of the edittext fields or will I have to reference each one?

My xml file structure is as follows:

<ScrollView>
    <LinearLayout android:id="@+id/MainParent">
        <LinearLayout>
            TextView
            EditText
        </LinearLayout>
        <LinearLayout>
            TextView
            EditText
        </LinearLayout>
        <LinearLayout>
            TextView
            EditText
        </LinearLayout>
        EditText
        <LinearLayout>
            Button1
            Button2
        </LinearLayout>
    </LinearLayout>
</ScrollView>

Snippet from Java File:

ViewGroup group = (ViewGroup)findViewById(R.id.MainParent);
       for (int i = 0, count = group.getChildCount(); i < count; ++i) {
           View view = group.getChildAt(i);
               if (view instanceof EditText) {
                   ((EditText)view).setText("");
       }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:28:14+00:00Added an answer on June 12, 2026 at 11:28 pm

    If you are not interested in referencing each EditText specifically, I’d make a recursive function to handle the hierarchy.

    public void clearAll(ViewGroup root) {
        for (int i = 0, j = root.getChildCount(); i < j, i++) {
            View view = root.getChildAt(i);
            if (view instanceof ViewGroup) {
                clearAll((ViewGroup) view);
                continue;
            }
            if (view instanceof EditText) {
                ((EditText) view).setText("");
                continue;
            }
        }
    }
    

    Then you just call:

    clearAll((ViewGroup) findViewById(R.id.MainParent));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I looked at other questions regarding this problem and tried their solutions, but it
I have looked at other questions and answers regarding this, but can't seem to
I have looked at the other questions related to this problem but I do
Just to make this clear, I have looked at the other questions on this
I have looked for similar questions, but could find none other than the difference
I've looked through several other questions here and on other sites regarding this issue,
I've looked at a number of other similar questions, but the methods given seem
i have looked through other related questions but none of them giving me right
I have looked at the other questions on here about this. It isn't working.
I have looked at several other questions but I can't seem to figure any

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.