kayveesin
kayveesin

Reputation: 433

unable to get the working of this for loop

Please explain how this for loop works:

  Button submit = new Button(this);
submit.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View arg0) {
        for (EditText editText : editTexts) {
            editText.getText().toString();
            // whatever u want to do with the strings
        }
    }

Particularly, what does the for (EditText editText : editTexts) part do?

Upvotes: 0

Views: 58

Answers (3)

ObieMD5
ObieMD5

Reputation: 2657

This is saying for each EditText view within editTexts (an array or collection).

EXAMPLE
If editTexts was an array of editTexts like et1,et2,et3,et4 This loop would start at et1 accomlish all the work in the inner loop then go to et2 and do the same thing over and over until after et4 it will exit the loop.

Upvotes: 2

Tarsem Singh
Tarsem Singh

Reputation: 14199

its for-each loop, EditText editText within array of editTexts

Upvotes: 0

Rémi F
Rémi F

Reputation: 1335

You should look at the type of 'editTexts'. It seems to be a simple 'foreach' loop in java.

Upvotes: 0

Related Questions