I am trying to populate a list view from an ArrayList but for some reason it only grabs the last record. The array holds the data correctly and if I change the I to a number it will print the selected value.
My code is below any help would be appreciated.
ArrayList<String> tests = new ArrayList();
for(HashMap<String, String> test : outageData){
String outagenumber = test.get("outagenum");
Log.v("Outage",outagenumber);
tests.add(outagenumber);
}
SectionListItem[] exampleArray = null;
for(int i = 0; i < tests.size(); i++) {
exampleArray = new SectionListItem[]{
new SectionListItem("test", tests.get(i)),
};
}
CustomOutageDetailListAdapter adapter = new CustomOutageDetailListAdapter(this, exampleArray);
sectionAdapter = new SectionListAdapter(getLayoutInflater(),
adapter);
This is the adapter for fill List.
public class SectionOutageListItem {
public Object item;
public String section;
public SectionOutageListItem(final Object item, final String section) {
super();
this.item = item;
this.section = section;
}
@Override
public String toString() {
return item.toString();
}
}
Updated Code:
SectionOutageListItem[] exampleArray = new SectionOutageListItem[outnums.size()];
for(int i = 0; i < outnums.size(); i++) {
exampleArray[i] =
new SectionOutageListItem("Impact", impacted.get(i), "Outage No. " + outnums.get(i)),
new SectionOutageListItem("status", status.get(i), "Outage No. " + outnums.get(i));
}
CustomOutageDetailListAdapter adapter = new CustomOutageDetailListAdapter(this, exampleArray);
sectionAdapter = new SectionOutageListAdapter(getLayoutInflater(),
adapter);