How do I get data from a specific ArrayList row using a loop? I've added those value into ArrayList as follow.
myArrayList.add("ID007");
myArrayList.add("PPShein");
myArrayList.add("Male");
myArrayList.add("7-Apr-1983");
I want to do something like this:
for (i=0; i < myarr.size(); i++)
{
getName = myarr[2].value();
}
It's because of I want to display as follow.
myTextView.setText(getName); //myName : "ppshein"
ArrayList has a handy method called get, which takes in an index. What you may be used to is using Arrays, such as array[3] to access the 4th element. With an ArrayList, use the get method:
for(int i = 0; i < myArr.size(); i++) {
System.out.println(myArr.get(i)); //prints element i
}
You just call the row...
String getName;
int rowValue = 2;
getName = myarr.get(rowValue);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With