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

  • SEARCH
  • Home
  • 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 9198907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:23:59+00:00 2026-06-17T22:23:59+00:00

I’m working on Eclipse ADT. I came across task where I need to check

  • 0

I’m working on Eclipse ADT. I came across task where I need to check a number of EditText fields, so I decided I could use FOR loop to check all of them with less coding.

For instance I have:

EditText editTxt1 = (EditText) findViewById(R.id.editText1);
EditText editTxt2 = (EditText) findViewById(R.id.editText2);
EditText editTxt3 = (EditText) findViewById(R.id.editText3);
EditText editTxt4 = (EditText) findViewById(R.id.editText4);
...

and I want to check them with for loop like so:

int x;

for (x=3; x<=4; x++) {
    if (editTxt"x".getText().toString().equals("something")) do smthng...
}

Is it possible at all, or I have to go through long way coding?

  • 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-17T22:24:00+00:00Added an answer on June 17, 2026 at 10:24 pm

    You could do this via reflection as Quoi points out, but this is generally not a good a idea.

    It would be better just to add your objects to a list or a map:

    List<EditText> list = new ArrayList<EditText>();
    EditText editTxt1 = (EditText) findViewById(R.id.editText1);
    list.add(editTxt1);
    EditText editTxt2 = (EditText) findViewById(R.id.editText2);
    list.add(editTxt2);
    EditText editTxt3 = (EditText) findViewById(R.id.editText3);
    list.add(editTxt1);
    EditText editTxt4 = (EditText) findViewById(R.id.editText4);
    

    Now we can cycle through the list and use the index to check which edit text was being called.

    int i = 0;
    for (EditText e : list) {
        if(e.getText().toString().equals("something")) {
            System.out.println("editText" + i + " equals something");
            // do stuff
        }
        i++;
    }
    

    You could also use a Map to do this, this would allow you to have a name value against your objects to help give you a better reference to check what object was being called. This takes a bit more work, but might be use

    Map<EditText, String> map = new HashMap<EditText, String>();
    EditText editTxt1 = (EditText) findViewById(R.id.editText1);
    map.put(editTxt1, "editTxt1");
    EditText editTxt2 = (EditText) findViewById(R.id.editText2);
    list.add(editTxt2, "editTxt2");
    
    for (Entry<String, String> e : map.entrySet()) {
        if(e.getValue().equals("something")) {
            System.out.println(e.getKey() + " was equal to somethihng");
        }
    }
    

    PS – Never use == to compare Strings, it won’t always work!!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am confused How to use looping for Json response Array in another Array.
I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I need a function that will clean a strings' special characters. I do NOT
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.