jeudi 7 avril 2016

Returning data from SQLite depending on the day - Variables the same but not recognising?

I have a method that pulls information from an SQLite database and depending on what the current day is.

I compare the day in the database to the current day, but it returns nothing!

So I outputted the variables in Toast's that I was comparing and they come back exactly the same, but the if statement doesn't work?

Here is my method:

public void getTodaysModules(String sessionName)
    {
        List<tableStudents> studentModules = db.getStudentsModules(sessionName);    

        if (!studentModules.isEmpty())
        {           
        for (tableStudents session: studentModules)
        {
            //Save modules to string
            String module1 = session.modules.toString();
            String module2 = session.modules1.toString();
            String module3 = session.modules2.toString();               
            String today = getCurrentDay().toString();          
            Toast.makeText(MainActivity.this, "Today is: " + today, Toast.LENGTH_LONG).show(); 
            TextView event1 = (TextView)findViewById(R.id.event1);
            event1.setText(today + "'s Events:");

            List<tableModules> moduleDayList = db.getModuleTime(module1, module2, module3, today, today);
              for (tableModules module: moduleDayList) { 
                  Toast.makeText(MainActivity.this, "Name" + module.modulename.toString(), Toast.LENGTH_LONG).show(); 
                  Toast.makeText(MainActivity.this, "Lecture date" + module.modulelecturedate.toString(), Toast.LENGTH_LONG).show(); 
                  Toast.makeText(MainActivity.this, "Module Seminar Date" + module.moduleseminardate.toString(), Toast.LENGTH_LONG).show(); 

                  if(module.modulelecturedate.toString() == today)
                  {                      
                      event1.setText("Your Lecture for" + module.modulename.toString() + "is at" + module.modulelecturetime.toString());
                  }                   
                  if (module.moduleseminardate.toString() == today)
                  {                 
                      event1.setText("Your Seminar for" + module.modulename.toString() + "is at" + module.moduleseminartime.toString());
                  }
                  else if (module.modulelecturedate.toString() != today) 
                  {
                      if (module.moduleseminardate.toString() != today)
                      {
                      event1.setText("You have no seminars/lectures today");
                      }
                  }             
                }
            }
        }
        else
        {
            Toast.makeText(MainActivity.this, "N", Toast.LENGTH_LONG).show();           
        }

    }

It displays the "You have no seminars/lectures today", however the toasts above the if statements showing the current day, then the lecture date (which is the day) and seminar date (which is also just the day).

I'm not sure what's going on if both variables are exactly the same, is it the if statement?

Thanks

Aucun commentaire:

Enregistrer un commentaire