-3

I'm making a task manager application where I require the following details:- name (string), description (string), date (long) and importance (int).

I am currently stuck on figuring out how to get the date and also see if date from calendarView has been selected.

TextView name, description, importance;
    CalendarView calendar;
    Button submit;
    ArrayList<Task> myTasks = new ArrayList<>();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_create_task);

    name = (TextView)findViewById(R.id.CreateTaskNameET);
    description = (TextView)findViewById(R.id.CreateTaskDescriptionET);
    importance = (TextView)findViewById(R.id.CreateTaskImportanceET);
    calendar = (CalendarView) findViewById(R.id.CreateTaskCalender);

    submit = (Button)findViewById(R.id.CreateTaskSubmitBtn);

    submit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Task myTask = new Task(name.getText().toString(),
                    description.getText().toString(),
                    calendar.getDate(),
                    Integer.parseInt(importance.getText().toString()));

            myTasks.add(myTask);
        }
    });

}

public void validateRule(EditText name, EditText description, CalendarView calendar, EditText importance){
    if(name.getText().equals("")){

    }
    else if(description.getText().equals("")){

    }
    else if(calendar.getDate()){

    }
}

Once again, how can i determine if the date has been selected as it's one of my validation rules? Thanks

Yoni
  • 1,346
  • 3
  • 16
  • 38
Nero
  • 1,058
  • 1
  • 9
  • 25

1 Answers1

1

Please set a listener to the calendar view object which will allow you to create custom actions once the listener is triggered on a date change. OnDateChangeListener is a class method of calendar view object, more information can be accessed by referring to the code for CalendarView class.

calendar.setOnDateChangeListener(new OnDateChangeListener() {

            @Override
            public void onSelectedDayChange(CalendarView view, int year, int month,
                    int dayOfMonth) {
im404
  • 26
  • 4
  • 1
    You should give more context/explanation for the code. Please take a look at the site [tour] as well as [answer]. – EJoshuaS - Stand with Ukraine Sep 09 '17 at 22:37
  • 1
    Code-only answers are discouraged because they do not explain how they resolve the issue in the question. Please update your answer to explain what this does and how it addresses the problem. Please review [How do I write a good answer](https://stackoverflow.com/help/how-to-answer) – FluffyKitten Sep 10 '17 at 08:10
  • Thank you for the helpful feedback. I have added an explanation to the answer. – im404 Sep 11 '17 at 03:19
  • Sorry for the late response and it makes complete sense now. I added the OnDateChangeListener and added a boolean variable and set it to True once the listener is triggered. Then I put the "if boolean == true" as my condition of validation. Question answered – Nero Sep 16 '17 at 09:36