next button in android ....home page

In my android application In the home page I have 2 buttons one is next > and the other is privous < when the next is clicked ....the date and prayers time should be for the next day .....and the same for previous but invers.... i toke the date from calender..... but the prayers time are stored in database sqlit.

can anybody help me in creating this code ....I'm new in android please help

this code is bringing the time from my database

void getTime( ) {

   Calendar c = Calendar.getInstance();
   int day = c.get(DATE);
   int month = c.get(MONTH);
    String[] monthNames ={"january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"};

    PrayerTimeRecord times =UILApplication.dataBase.getTime(day, monthNames[month]);
    fajrtimeView.setText(times.fajrtime);
    zuhrtimeView.setText(times.zuhrtime);
    asrtimeView.setText(times.asrtime);
    maghribtimeView.setText(times.maghribtime);
    ishatimeView.setText(times.ishatime);

}

Answers


Maybe this is what you are looking for. You can add or subtract days from the calendar instance using

 c.add(Calendar.DATE, n);  // add n to the calendars current date
 c.add(Calendar.DATE, -n);  // subtract n from the calendars current date

Edit: Firstly put your calendar variable at the top of the class so it can be referenced from anywhere within your class, for example; then add this to your next button

_yourNextButton.setOnClickListener(new OnClickListener()
{
     @Override
     public void onClick(View v)
     {
        _yourCalendar.add(Calendar.DATE, 1); // Add 1 to the calendars current date.
        updateGUI(); // Update your text views based on the new date!
     }
});

then move your code to update your textviews to a method so that they can be called again and again without duplicating code :)

// Rename to whatever you like!
protected void updateGUI()
{   
    // Your current code; just moved and referring to the different calendar
    int day = _yourCalendar.get(DATE);
    int month = _yourCalendar.get(MONTH);
    String[] monthNames = {"january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"};

    PrayerTimeRecord times = UILApplication.dataBase.getTime(day, monthNames[month]);
    fajrtimeView.setText(times.fajrtime);
    zuhrtimeView.setText(times.zuhrtime);
    asrtimeView.setText(times.asrtime);
    maghribtimeView.setText(times.maghribtime);
    ishatimeView.setText(times.ishatime);
}

Obviously this will need tweaking because you'll need to fix some of the references to your variables because I don't have your complete code. But that's the general idea I think, hope that helped :)

What about going back a day? Add a click listener to your previous button and put _yourCalendar.add(Calendar.DATE, -1) instead.


Need Your Help