parik dhakan
parik dhakan

Reputation: 787

Make sequence array for edittext value

I have 270 EditTexts. Now I want to get the value from each EditText and put it into a String[] concurrently and compare it for results. Unfortunately I can't do it. How can I achieve it?

One more thing I want to check if correct or not. If not correct I just get this correct answer in EditText which is wrong.

Upvotes: 0

Views: 53

Answers (1)

arodriguezdonaire
arodriguezdonaire

Reputation: 5562

The idea is that you have to iterate over all your EditText boxes and save its result in the string[]. To do this I recommend you to have this 270 EditText boxes inside a ViewGroup and then iterate over the childs of the ViewGroup. You can do something like this:

LinearLayout layout = (LinearLayout)findViewById(R.id.layout); // The ViewGroup mentioned which should have the 270 EditText boxes inside
String[] myStringArray = iterateOverViews(layout);

Where iterateOverViews(layout) calls to this function:

public String[] iterateOverLayout(LinearLayout layout) {
    String[] ret = new String[270];
    for (int i = 0; i < 270; i++) {
        EditText box = layout.getChildAt(i);
        ret[i] = box.getText();
    }
    return ret;
}

Upvotes: 2

Related Questions