简体   繁体   中英

input field date validations

I have three fields

  1. Current Date
  2. Next Due Date
  3. Status, It is spinner having values open, close, all

My java code is:

    date_txtbx = (EditText) findViewById(R.id.date_txtbx);
        date_txtbx.setText(" "
                + String.valueOf(java.text.DateFormat.getDateTimeInstance()
                        .format(Calendar.getInstance().getTime())));

next_due_on_txtbx = (EditText) findViewById(R.id.next_due_on_txtbx);
        next_due_on_txtbx.setText(non_ticket_task.next_due_on);



       status = (Spinner) findViewById(R.id.status_spinner);
     // Create an ArrayAdapter using the string array and a default spinner layout
     ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
             R.array.Status_array, android.R.layout.simple_dropdown_item_1line);
     // Specify the layout to use when the list of choices appears
     adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
     // Apply the adapter to the spinner
     status.setAdapter(adapter);

I want that next due date is disable when user select close status and if user input next due date less than or equal to current date it display error message that " Please insert date that is greater than current date ". How can it possible?? i just want these validations on **EditText** . Kindly guide. Any help would be appreciate.

apply condition:

   next_due_on_txtbx = (EditText) findViewById(R.id.next_due_on_txtbx);
        next_due_on_txtbx.setText(non_ticket_task.next_due_on);
        if (next_due_on_txtbx.after(date_txtbx))
        {
            Context count;
            Toast.makeText(count, "Starting date cannot be before Current date", Toast.LENGTH_LONG).show();
        }

Just check

 if (date1.after(date2))
{
    Toast.makeText(Your_Current_Activity.this, 
       "Starting date cannot be before Current date", Toast.LENGTH_LONG).show();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM