app/src/main/java/com/example/steve/todoandroid/editScreenFragment.java
//interfaces with the save button to pass data back into main activity and calls finish listener
interfaces with the save button to pass data back into main activity and calls finish listener
interfaces with the save button to pass data back into main activity and calls finish listener
public void initBtnSaveOnClickListener(View v)
    {
        Button btnSave = (Button) v.findViewById(R.id.btnSave);
        final View calledView = v;
        btnSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ToDoListActivity myActivity = (ToDoListActivity) getActivity();
                EditText editTask = (EditText) calledView.findViewById(R.id.etxEditItem);
                Spinner spnPriority = (Spinner) calledView.findViewById(R.id.priority);
                DatePicker dueDate = (DatePicker) calledView.findViewById(R.id.datePicker);
                String priority = spnPriority.getSelectedItem().toString();
                String editText = editTask.getText().toString();
                int month = dueDate.getMonth() +1 ;
                int day = dueDate.getDayOfMonth();
                int year = dueDate.getYear();
                if (editText.matches("")) {
                    AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create();
                    alertDialog.setTitle("Alert");
                    alertDialog.setMessage("List item cannot be blank");
                    alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                }
                            });
                    alertDialog.show();
                }
                else
                {
                    currentDB.setListItemString(editText);
                    currentDB.setPriority(priority);
                    currentDB.setDueDate(day,month,year);
                    myActivity.setMainActivityDB(currentDB);
                    onEditFinishedListener listener = (onEditFinishedListener) getActivity();
                    listener.onEditFinish(editText);
                    dismiss();  
                }
            }
        });
    }
public void initBtnSaveOnClickListener ( View v ) { Button btnSave = ( Button ) v . findViewById ( R . id . btnSave ) ; final View calledView = v ; btnSave . setOnClickListener ( new View . OnClickListener ( ) { @ Override public void onClick ( View view ) { ToDoListActivity myActivity = ( ToDoListActivity ) getActivity ( ) ; EditText editTask = ( EditText ) calledView . findViewById ( R . id . etxEditItem ) ; Spinner spnPriority = ( Spinner ) calledView . findViewById ( R . id . priority ) ; DatePicker dueDate = ( DatePicker ) calledView . findViewById ( R . id . datePicker ) ; String priority = spnPriority . getSelectedItem ( ) . toString ( ) ; String editText = editTask . getText ( ) . toString ( ) ; int month = dueDate . getMonth ( ) + 1 ; int day = dueDate . getDayOfMonth ( ) ; int year = dueDate . getYear ( ) ; if ( editText . matches ( "" ) ) { AlertDialog alertDialog = new AlertDialog . Builder ( getActivity ( ) ) . create ( ) ; alertDialog . setTitle ( "Alert" ) ; alertDialog . setMessage ( "List item cannot be blank" ) ; alertDialog . setButton ( AlertDialog . BUTTON_NEUTRAL , "OK" , new DialogInterface . OnClickListener ( ) { public void onClick ( DialogInterface dialog , int which ) { dialog . dismiss ( ) ; } } ) ; alertDialog . show ( ) ; } else { currentDB . setListItemString ( editText ) ; currentDB . setPriority ( priority ) ; currentDB . setDueDate ( day , month , year ) ; myActivity . setMainActivityDB ( currentDB ) ; onEditFinishedListener listener = ( onEditFinishedListener ) getActivity ( ) ; listener . onEditFinish ( editText ) ; dismiss ( ) ; } } } ) ; }
interfaces with the save button to pass data back into main activity and calls finish listener
interfaces with the save button to pass data back into main activity and calls finish listener
//ToDoListActivity myActivity = new ToDoListActivity(); //for some reason, the below view is always null so I end up having to pass through the view // that comes in with the click. //initialize various elemnts on the fragment: can we put this into a function of somesort somehow? //date picker normalizes month while month starts at 0,, so need to add 1 when saving. //set all the various DB attributes.Can toss this in a separate function if we need. //pass this stuff back to main activity and end fragment. //is this right?