java - Holding multiple values at same index in array -


my code retrieves number of steps, output instruction @ each step via loop. there title, description, video, , audio. however, trying think of way store each variable structure. came with, don't think array can store multiple values @ same index.

for(int = 0; < qrdata.number_steps; i++){         system.out.println("inside loop");         array[i].settitle(btn_instructions.get(i));         array[i].setdescription(instruction_row.get(i));         array[i].setinstructionvideo(videos.get(i));         array[i].setaudioinstruction(audio.get(i)); } 

what better way store these values, easy retrieve later? i'm pretty sure method doesn't work.

you should create object like:

public class datastorage{    private string title;    private string description;    private file audiofile;    private file videofile;    public datastorage(string title, string description, file audiofile, file videofile){     this.title = title;     this.description = description;     this.audiofile = audiofile;     this.videofile = videofile;   }    public string gettitle(){     return this.title;   }  //similar "description", "audiofile" , "videofile"  //... } 

for datastorage recommend using arraylist, because dynamic , can add new elements while programm running. can save data in there loop:

arraylist<datastorage> storage = new arraylist<>();  for(int = 0; < qrdata.number_steps; i++){     storage.add(new datastorage(btn_instructions.get(i),instruction_row.get(i),     videos.get(i),audio.get(i)); } 

this basic concept of object oriented programming define classes store custom data.

you can data out of array calling "getters" of datastorage class. example:

string title = storage.get(itemnumber).gettitle(); 

gives value of "itemnumber" title.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -