1

Is there a way to store EditText into a list array. For example,

n1I1 = (EditText) findViewById(R.id.etN1I1);
n1I2 = (EditText) findViewById(R.id.etN1I2);
n1I3 = (EditText) findViewById(R.id.etN1I3);
n2I1 = (EditText) findViewById(R.id.etN2I1);
n2I2 = (EditText) findViewById(R.id.etN2I2);
n2I3 = (EditText) findViewById(R.id.etN2I3);

into

FirstList[]={n1I1,n1I2,n1I3}
SecondList[]={n2I1,n2I2,n2I3}.

I would like to have it like this so that it is easy for me to keep track of number input by user. While at it, how can I store double(eg. 31.12) value into an arraylist?

Thanks.

0

2 Answers 2

1

You have 2 options:

    //Array
    EditText[] FirstList = {n1I1,n1I2,n1I3};

    //or ArrayList      
   List<EditText> FirstList = new ArrayList<EditText>(){{
     add(n1I1);
     add(n1I2);
     add(n1I3);
   }};
Sign up to request clarification or add additional context in comments.

Comments

1

use an ArrayList object, not a regular array:

ArrayList<EditText> firstList = new ArrayList<EditText>();
firstList.add(n1I1);
firstList.add(n1I2);
firstList.add(n1I3);

ArrayList<EditText> secondList = new ArrayList<EditText>();
secondList.add(n2I1);
secondList.add(n2I2);
secondList.add(n2I3);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.