0

I am not really sure how to word this question, so I did the best I could in that aspect. So I am having a problem with creating a DatePicker in my Activity. This is the code that is giving me an error:

EditEventActivity.java

DateDialogFragment frag = DateDialogFragment.newInstance(this, new 
DateDialogFragmentListener() {

            @Override
            public void updateChangeDate(int year, int month, int day) {
                // TODO Auto-generated method stub

            }
        }, sYear, sMonth, sDay);

The newInstance() method I have there is whats giving me the error. The error is this:

The method newInstance(Context, AddEventActivity.DateDialogFragmentListener, int, int,
int) in the type DateDialogFragment is not applicable for the arguments 
(EditEventActivity, new EditEventActivity.DateDialogFragmentListener(){}, int, int, 
int)

Now the DateDialogFragment is located in its own file. I don't think I need to post that. It is what it is. But my interface is in AddEventActivity.java. Now this is what I am confused about. My static method, newInstance() from DateDialogFragment takes DateDialogFragmentListenernot AddEventActivity.DateDialogFragmentListener. So I assume thats what the problem is. But then again, I am not sure, which is what I need help understanding. Thanks you in advance.

Actually. I also figue I might as well include the newInstance() method:

DateDialogFragment.java

public static DateDialogFragment newInstance(Context context, DateDialogFragmentListener 
listener, int year, int month, int day) {
    DateDialogFragment dialog = new DateDialogFragment();
    mContext = context;
    mListener = listener;
    mYear = year;
    mMonth = month;
    mDay = day;
    Bundle args = new Bundle();
    args.putString("title", "Set Date");
    dialog.setArguments(args);
    return dialog;
}
4

2 回答 2

3

You pass too many arguments to the newInstance(...) method. Only pass sYear, sMonth and sDay once rather than twice.

Edit You're having here two classes with the same simple name but they're different classes and therefore different types. Just pass an instance of the right class.

DateDialogFragment frag = DateDialogFragment.newInstance(
    this, 
    new AddEventActivity.DateDialogFragmentListener() {

        @Override
        public void updateChangeDate(int year, int month, int day) {
            // TODO Auto-generated method stub

        }
    }, sYear, sMonth, sDay);

.. or correct the signature of your newInstance() method if you need to pass a EditEventActivity.DateDialogFragmentListener.

于 2012-07-01T21:29:37.343 回答
1

Assuming that EditEventActivity.DateDialogFragmentListener extends AddEventActivity.DateDialogFragmentListener, your newInstance method takes 3 ints after the listener and you are passing 6 ints - you probably meant:

DateDialogFragment frag = DateDialogFragment.newInstance(this, new DateDialogFragmentListener() {

        @Override
        public void updateChangeDate(int year, int month, int day) {
            // TODO Auto-generated method stub

        }
    }, sYear, sMonth, sDay); //removed the last 3 arguments

EDIT
Following your edit, back to my first comment: does EditEventActivity.DateDialogFragmentListener extend AddEventActivity.DateDialogFragmentListener?

于 2012-07-01T21:30:06.953 回答