I am new to Android and Java and can't figure out this seemingly basic for loop setup to create an array of objects from the data in two other arrays.
It works this way, but this doesn't feel very sophisticated.
// RefineMenuItem is a public class
public class RefineMenuItem {
private int imageIcon;
private String title;
}
// imageIcon and title are arrays with seven values in them
int[] imageItems = { ... }
String[] menuItems = { ... }
// Create the RefineMenu Objects
RefineMenuItem item1 = new RefineMenuItem(imageItems[0],menuItems[0]);
RefineMenuItem item2 = new RefineMenuItem(imageItems[1],menuItems[1]);
RefineMenuItem item3 = new RefineMenuItem(imageItems[2],menuItems[2]);
RefineMenuItem item4 = new RefineMenuItem(imageItems[3],menuItems[3]);
RefineMenuItem item5 = new RefineMenuItem(imageItems[4],menuItems[4]);
RefineMenuItem item6 = new RefineMenuItem(imageItems[5],menuItems[5]);
RefineMenuItem item7 = new RefineMenuItem(imageItems[6],menuItems[6]);
// Add the RefineMenu Objects to an ArrayList
ArrayList<RefineMenuItem> refineMenuList = new ArrayList<>();
refineMenuList.add(item1);
refineMenuList.add(item2);
refineMenuList.add(item3);
refineMenuList.add(item4);
refineMenuList.add(item5);
refineMenuList.add(item6);
refineMenuList.add(item7);
I believe I need to create the array of objects first and then add to it based on this question.
RefineMenuItem[] arr = new RefineMenuItem[7];
Then I believe I should use a for loop to add to the array, but this is where I'm getting stuck and can't figure it out after researching. Help to point me in the right direction is appreciated!