Reputation: 13
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.
Upvotes: 1
Views: 7439
Reputation: 10193
You have 2 options:
//Array
EditText[] FirstList = {n1I1,n1I2,n1I3};
//or ArrayList
List<EditText> FirstList = new ArrayList<EditText>(){{
add(n1I1);
add(n1I2);
add(n1I3);
}};
Upvotes: 1
Reputation: 5909
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);
Upvotes: 1