diff --git a/app/src/main/java/com/example/coen390_assignment2/Views/MainActivity.java b/app/src/main/java/com/example/coen390_assignment2/Views/MainActivity.java index 94a7fa1..b7d67e3 100644 --- a/app/src/main/java/com/example/coen390_assignment2/Views/MainActivity.java +++ b/app/src/main/java/com/example/coen390_assignment2/Views/MainActivity.java @@ -48,15 +48,15 @@ public class MainActivity extends AppCompatActivity { studentProfileDBHelper = new StudentProfileDBHelper(getApplicationContext()); initAddProfileActionButton(showDialogButton); + + // surname when true, ID when false + profileNameDisplayMode = true; } @Override protected void onStart() { super.onStart(); - // surname when true, ID when false - profileNameDisplayMode = true; - List studentProfiles = studentProfileDBHelper.getAllStudentProfile(getApplicationContext()); // by default sort by surname @@ -86,6 +86,26 @@ public class MainActivity extends AppCompatActivity { return true; } + // toggle Display mode + @Override + public boolean onOptionsItemSelected(MenuItem item) { + int id = item.getItemId(); + + if (id == R.id.toggle_profiles_display_mode && toggle.getTitle() == "By ID") { + profileNameDisplayMode = false; + onStart(); + + return true; + } else if (id == R.id.toggle_profiles_display_mode && toggle.getTitle() == "By Surname"){ + profileNameDisplayMode = true; + + onStart(); + + return true; + } + + return super.onOptionsItemSelected(item); + } protected String[] showStudentProfileList(List studentProfiles, boolean profileNameDisplayMode){ // Create a new list for sorted profiles List sortedProfiles = new ArrayList<>(studentProfiles);