0

hey guys i have text views and when a user clicks on each text view a date-picker shows up.I have eight text views on the same page and they are ordered in their chronological order.The challenge now is that i want the first date time picker to show the date starting from today going onward and the next date-time picker should only show the dates that are greater than the date selected in the first text view. The third should also show dates that are greater than the one selected in the second text view .The current code i have is

public class  General extends Fragment {
        TextView onlinee, orientationn, semesterstarts, semesterbreakstarts, semesterbreakends, examstarts, examends, semesterends;
        Button btncalendarr;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_general, container, false);
        onlinee = (TextView)rootView.findViewById(R.id.grestarts);
        orientationn=(TextView) rootView.findViewById(R.id.gorstart);
        semesterstarts= (TextView) rootView.findViewById(R.id.gstart);
        semesterbreakstarts = (TextView)rootView.findViewById(R.id.semstart);
        semesterbreakends = (TextView) rootView.findViewById(R.id.semend);
        examstarts= (TextView) rootView.findViewById(R.id.exstart);
        examends= (TextView) rootView.findViewById(R.id.exend);
        semesterends=(TextView) rootView.findViewById(R.id.semsend);
        btncalendarr = (Button) rootView.findViewById(R.id.btncalendar);
        onlinee.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                Calendar mcurrentDate = Calendar.getInstance();
                int mYear = mcurrentDate.get(Calendar.YEAR);
                int mMonth = mcurrentDate.get(Calendar.MONTH);
                int mDay = mcurrentDate.get(Calendar.DAY_OF_MONTH);
                DatePickerDialog mDatePicker;
                mDatePicker = new DatePickerDialog(General.this.getActivity(), new DatePickerDialog.OnDateSetListener() {
                    public void onDateSet(DatePicker datepicker, int selectedyear, int selectedmonth, int selectedday) {
                    // TODO Auto-generated method stub
                    /*      Your code   to get date and time    */
                        selectedmonth = selectedmonth + 1;
                        onlinee.setText("" + selectedday + "/" + selectedmonth + "/" + selectedyear);
                    }
                    }, mYear, mMonth, mDay);
                    mDatePicker.setTitle("Select Date");
                    mDatePicker.show();
                 }
        });
        orientationn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

        Calendar mcurrentDate = Calendar.getInstance();
        int mYear = mcurrentDate.get(Calendar.YEAR);

        int mMonth = mcurrentDate.get(Calendar.MONTH);
        int mDay = mcurrentDate.get(Calendar.DAY_OF_MONTH);

        DatePickerDialog mDatePicker;
        mDatePicker = new DatePickerDialog(General.this.getActivity(), new DatePickerDialog.OnDateSetListener() {
        public void onDateSet(DatePicker datepicker, int selectedyear, int selectedmonth, int selectedday) {
            // TODO Auto-generated method stub
                /*      Your code   to get date and time    */
            selectedmonth = selectedmonth + 1;
            orientationn.setText("" + selectedday + "/" + selectedmonth + "/" + selectedyear);
        }
        }, mYear, mMonth, mDay);
        mDatePicker.setTitle("Select Date");
        mDatePicker.show();
            }
        });
        semesterstarts.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
        Calendar mcurrentDate = Calendar.getInstance();
        int mYear = mcurrentDate.get(Calendar.YEAR);
        int mMonth = mcurrentDate.get(Calendar.MONTH);
        int mDay = mcurrentDate.get(Calendar.DAY_OF_MONTH);
        DatePickerDialog mDatePicker;
        mDatePicker = new DatePickerDialog(General.this.getActivity(), new DatePickerDialog.OnDateSetListener() {
            public void onDateSet(DatePicker datepicker, int selectedyear, int selectedmonth, int selectedday) {
            // TODO Auto-generated method stub
                /*      Your code   to get date and time    */
            selectedmonth = selectedmonth + 1;
            semesterstarts.setText("" + selectedday + "/" + selectedmonth + "/" + selectedyear);
            }
        }, mYear, mMonth, mDay);
        mDatePicker.setTitle("Select Date");
        mDatePicker.show();
        }
                    });
        semesterbreakstarts.setOnClickListener(new View.OnClickListener() {
            @Override
        public void onClick(View view) {
        Calendar mcurrentDate = Calendar.getInstance();
        int mYear = mcurrentDate.get(Calendar.YEAR);
        int mMonth = mcurrentDate.get(Calendar.MONTH);
        int mDay = mcurrentDate.get(Calendar.DAY_OF_MONTH);

        DatePickerDialog mDatePicker;
        mDatePicker = new DatePickerDialog(General.this.getActivity(), new DatePickerDialog.OnDateSetListener() {
            public void onDateSet(DatePicker datepicker, int selectedyear, int selectedmonth, int selectedday) {
                // TODO Auto-generated method stub
                    /*      Your code   to get date and time    */
                selectedmonth = selectedmonth + 1;
                semesterbreakstarts.setText("" + selectedday + "/" + selectedmonth + "/" + selectedyear);
            }
            }, mYear, mMonth, mDay);
            mDatePicker.setTitle("Select Date");
            mDatePicker.show();
        }
        });
            semesterbreakends.setOnClickListener(new View.OnClickListener() {
         @Override
         public void onClick(View view) {
             Calendar mcurrentDate = Calendar.getInstance();
             int mYear = mcurrentDate.get(Calendar.YEAR);
             int mMonth = mcurrentDate.get(Calendar.MONTH);
             int mDay = mcurrentDate.get(Calendar.DAY_OF_MONTH);

             DatePickerDialog mDatePicker;
             mDatePicker = new DatePickerDialog(General.this.getActivity(), new DatePickerDialog.OnDateSetListener() {
                 public void onDateSet(DatePicker datepicker, int selectedyear, int selectedmonth, int selectedday) {
                     // TODO Auto-generated method stub
                /*      Your code   to get date and time    */
                     selectedmonth = selectedmonth + 1;
                     semesterbreakends.setText("" + selectedday + "/" + selectedmonth + "/" + selectedyear);
                 }
             }, mYear, mMonth, mDay);
             mDatePicker.setTitle("Select Date");
             mDatePicker.show();
         }
     });
        examstarts.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
            Calendar mcurrentDate = Calendar.getInstance();
            int mYear = mcurrentDate.get(Calendar.YEAR);
            int mMonth = mcurrentDate.get(Calendar.MONTH);
            int mDay = mcurrentDate.get(Calendar.DAY_OF_MONTH);

            DatePickerDialog mDatePicker;
            mDatePicker = new DatePickerDialog(General.this.getActivity(), new DatePickerDialog.OnDateSetListener() {
                public void onDateSet(DatePicker datepicker, int selectedyear, int selectedmonth, int selectedday) {
                    // TODO Auto-generated method stub
                        /*      Your code   to get date and time    */
                    selectedmonth = selectedmonth + 1;
                    examstarts.setText("" + selectedday + "/" + selectedmonth + "/" + selectedyear);
                }
            }, mYear, mMonth, mDay);
            mDatePicker.setTitle("Select Date");
            mDatePicker.show();
            }
            });

            examends.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Calendar mcurrentDate = Calendar.getInstance();
                    int mYear = mcurrentDate.get(Calendar.YEAR);
                    int mMonth = mcurrentDate.get(Calendar.MONTH);
                    int mDay = mcurrentDate.get(Calendar.DAY_OF_MONTH);

                DatePickerDialog mDatePicker;
                mDatePicker = new DatePickerDialog(General.this.getActivity(), new DatePickerDialog.OnDateSetListener() {
                    public void onDateSet(DatePicker datepicker, int selectedyear, int selectedmonth, int selectedday) {
                        // TODO Auto-generated method stub
                            /*      Your code   to get date and time    */
                        selectedmonth = selectedmonth + 1;
                        examends.setText("" + selectedday + "/" + selectedmonth + "/" + selectedyear);
                    }
                }, mYear, mMonth, mDay);
                mDatePicker.setTitle("Select Date");
                mDatePicker.show();
                }
                    });
                     semesterends.setOnClickListener(new View.OnClickListener() {
                         @Override
                         public void onClick(View view) {
             Calendar mcurrentDate = Calendar.getInstance();
             int mYear = mcurrentDate.get(Calendar.YEAR);
             int mMonth = mcurrentDate.get(Calendar.MONTH);
             int mDay = mcurrentDate.get(Calendar.DAY_OF_MONTH);

             DatePickerDialog mDatePicker;
             mDatePicker = new DatePickerDialog(General.this.getActivity(), new DatePickerDialog.OnDateSetListener() {
                 public void onDateSet(DatePicker datepicker, int selectedyear, int selectedmonth, int selectedday) {
                     // TODO Auto-generated method stub
                /*      Your code   to get date and time    */
                     selectedmonth = selectedmonth + 1;
                                 semesterends.setText("" + selectedday + "/" + selectedmonth + "/" + selectedyear);
                             }
                         }, mYear, mMonth, mDay);
                         mDatePicker.setTitle("Select Date");
                         mDatePicker.show();
                     }
                 });
                 btncalendarr.setOnClickListener(new View.OnClickListener() {
                     @Override
                     public void onClick(View view) {

             String online = onlinee.getText().toString();
             String orientation = orientationn.getText().toString();
             String simstart= semesterstarts.getText().toString();
             String simbstart = semesterbreakstarts.getText().toString();
             String sembreak = semesterbreakends.getText().toString();
             String examstart = examstarts.getText().toString();
             String examend = examends.getText().toString();
             String semmend = semesterends.getText().toString();
             if (online.isEmpty()||orientation.isEmpty()||simstart.isEmpty()||simbstart.isEmpty()||sembreak.isEmpty()||examstart.isEmpty()||examend.isEmpty()||semmend.isEmpty()){
                 android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(General.this.getActivity());
                 builder.setMessage("PLEASE FILL ALL FIELDS");
                 builder.setTitle("INPUT ERROR");
                 builder.setPositiveButton(android.R.string.ok, null);
                 android.app.AlertDialog dialog = builder.create();
                 dialog.show();
             }
             else {
                 new BackgroundTask(General.this.getActivity()).execute(online, orientation, simstart, simbstart, sembreak, examstart, examend, semmend);
              //   onlinee.setText("");
              //   orientationn.setText("");
               ///  semesterstarts.setText("");
               //  semesterbreakstarts.setText("");
                // semesterbreakends.setText("");
                /// examstarts.setText("");
                // examends.setText("");
                // semesterends.setText("");
                }
            }
        });
        return rootView;
    }
}
ozo
  • 763
  • 7
  • 13
Subdue
  • 3
  • 1

1 Answers1

0

i did't get your question clearly. but why you are not set the lest date of date picker by using this link. and you can do it by calculating your date into milliseconds and then compare two milliseconds. see this link.

it might be help full if i understand lill bit correctly.

Community
  • 1
  • 1
John smith
  • 1,781
  • 17
  • 27