• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps GetDay error

olijf

Newbie
hi all, I'm a beginning android developer. I am creating simple apps to learn more and the basics. however I didn't get past this one...
Code:
public void GetDay (View view){
        if (view == mBtnDay){
    
        Calendar cal = Calendar.getInstance();
            
        int day = mDpDate.getDayOfMonth();
        int month = mDpDate.getMonth();
        int year = mDpDate.getYear();            
        
        cal.set(year, month, day);
        

        DateFormat formatter = new SimpleDateFormat("EEEE");
        String date = formatter.format(cal.get(Calendar.DAY_OF_WEEK));
        Toast.makeText(this, "It's :"+  date + " today", Toast.LENGTH_LONG).show();
        }
    }
this is what I created. problem is when the button is pushed, you get in the toast : "It's : Thursday today". even after changing dates... clearly there is something wrong but I can't find what I am doing wrong.

need help. if you need any more information to help, post it.

Thanks in Advance
~Olijf
 
It isn't evident what the mDpDate field is, but you don't need it. This is enough:

Code:
Calendar cal = Calendar.getInstance();
DateFormat formatter = new SimpleDateFormat("EEEE");
String date = formatter.format(cal.get(Calendar.DAY_OF_WEEK));

Calendar.getInstance() will return an instance based on current time. If you want to change the day through a field, then post the code that modifies the mDpDate.
 
Back
Top Bottom