I'm very new to Android Dev, within this month, and I'm attempting to create a simple app to store 'medication' that a user needs to take each day. Currently, I have 7 String Arrays, one for each day of the week, all initialised with null values. They're fixed at 5 deep.
String[] mondayMed = new String[5];
String[] tuesdayMed = new String[5];
String[] wednesdayMed = new String[5];
String[] thursdayMed = new String[5];
String[] fridayMed = new String[5];
String[] saturdayMed = new String[5];
String[] sundayMed = new String[5];
The user can change day, which changes which array gets referenced, and then chose which of the 5 medication slots they wish to save their medication in. This is all fine and works well. The Arrays get changed, the textViews are updated etc. etc. For example here is the method I've made to set the TextViews to the content of whichever array and medication slot.
public void setMedication(int day, int medNum){
TextView medText = null;
if(medNum == 0){
medText = findViewById(R.id.medication1);
} else if (medNum == 1){
medText = findViewById(R.id.medication2);
} else if (medNum == 2){
medText = findViewById(R.id.medication3);
} else if (medNum == 3){
medText = findViewById(R.id.medication4);
} else if (medNum == 4){
medText = findViewById(R.id.medication5);
}
String medication;
if(day == 0){
medication = mondayMed[medNum];
medText.setText(medication);
} else if (day == 1){
medication = tuesdayMed[medNum];
medText.setText(medication);
} else if (day == 2) {
medication = wednesdayMed[medNum];
medText.setText(medication);
} else if (day == 3) {
medication = thursdayMed[medNum];
medText.setText(medication);
} else if (day == 4) {
medication = fridayMed[medNum];
medText.setText(medication);
} else if (day == 5) {
medication = saturdayMed[medNum];
medText.setText(medication);
} else if (day == 6) {
medication = sundayMed[medNum];
medText.setText(medication);
}
}
I'm aware this is far from ideal code, however for the time being I just want to get this working as simply as possible for myself to understand and develop further, later.
The Key thing I need now for this application to 'work' is a way to save these arrays when the application closes, or even simpler (I hear) when a button is pressed. And then, when the application is restarted, the saved data is read and the arrays are populated with said data. So that a user inputs their medication for the week, and then can open the app each day and see what meds they need to take.
I've done all of this within MainActivity, just for my own understanding and simplicity for my first app.