2016-04-13 37 views
-2

我是新来的android和我一直在尝试这一点的代码,但我得到以下错误: 错误:(20 8)错误:SyllabusFragment不是抽象的,不重写抽象方法createAssignmentClicked(分配)在onCreateInteractionListenerAndroid的错误:(20,8)错误:片段不抽象,不重写抽象方法

我无法理解什么是错我的代码 任何帮助,将不胜感激

SyllabusFragment:

import android.support.v4.app.Fragment; 
import android.app.AlarmManager; 
import android.app.DialogFragment; 
import android.app.PendingIntent; 
import android.content.Intent; 
import android.content.SharedPreferences; 
import android.preference.PreferenceManager; 
import android.support.design.widget.FloatingActionButton; 
import android.support.v4.app.FragmentTransaction; 
import android.os.Bundle; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 

import java.util.Calendar; 


public class SyllabusFragment extends Fragment 
    implements ColorDialogFragment.onCreateInteractionListener, 
    CreateAssignmentDialogFragment.onCreateInteractionListener, 
    classFragment.assignmentCall, 
    EditClassDialogFragment.onEditListener, 
    EditAssignmentDialogFragment.onEditListener, 
    EditColorDialogFragment.onCreateInteractionListener{ 

private String currentClass; 
/* Function returns the current parent class of activities being displayed. To only be called 
* when a assignment fragment is being displayed.*/ 
public String getParentClass() { 
    return currentClass; 
} 

/* Definition variables, indicating a certain fragment. */ 
private static final int CLASS_LIST_VIEW = 0; 
private static final int ASSIGNMENT_LIST_VIEW = 1; 

/* Variable, that is changed depending on which fragment is being displayed. */ 
private int currentFragment; 
/* A function which receives no arguments. Returns an integer value, indicating which fragment 
* is being displayed within the activity. */ 
public int getCurrentFragment() { 
    return currentFragment; 
} 

/* A function that is called when a new fragment is being displayed, which sets the title of 
* the activity, as well as sets the currentFragment variable to its proper value. */ 
public void setCurrentFragment(int fragment) { 
    switch (fragment) { 
     case CLASS_LIST_VIEW: 
      currentFragment = fragment; 
      //setTitle("Simple Planner"); 
      break; 
     case ASSIGNMENT_LIST_VIEW: 
      currentFragment = fragment; 
      /* Setting activity title to the parent class of the assignments being displayed. */ 
      // setTitle(getParentClass()); 
      break; 
    } 
} 

    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 

    View rootView = inflater.inflate(R.layout.fragment_syllabus, container, false); 

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); 
    //if (!prefs.getBoolean("firstTime", false)) { 
    // <---- run your one time code here(); 
    Calendar calendar = Calendar.getInstance(); 
    calendar.set(Calendar.HOUR_OF_DAY, prefs.getInt("hour", 19)); 
    calendar.set(Calendar.MINUTE, prefs.getInt("minute", 30)); 
    calendar.set(Calendar.SECOND, 0); 
    Intent intent1 = new Intent(getActivity(), AlaramReceiver.class); 
    PendingIntent pendingIntent = PendingIntent.getBroadcast(getActivity(), 0,intent1, PendingIntent.FLAG_UPDATE_CURRENT); 
    AlarmManager am = (AlarmManager) SyllabusFragment.this.getActivity().getSystemService(getActivity().ALARM_SERVICE); 
    am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 
      1000 * 60 * 60 * 24, pendingIntent); 
    //} 

    FloatingActionButton floatingActionButton = (FloatingActionButton)rootView.findViewById(R.id.fab); 

    /* Creating listener for Floating Action Button. */ 
    floatingActionButton.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      /* Action for when Floating Action Button is clicked. */ 
      switch (getCurrentFragment()) { 
       case CLASS_LIST_VIEW: { 
        DialogFragment dialogFragment = new CreateClassDialogFragment(); 
        dialogFragment.show(getActivity().getFragmentManager(), "dialog"); 
        break; 
       } 
       case ASSIGNMENT_LIST_VIEW: { 
        DialogFragment dialogFragment = new CreateAssignmentDialogFragment(); 
        Bundle args = new Bundle(); 
        args.putString("parent_class", getParentClass()); 
        dialogFragment.setArguments(args); 
        dialogFragment.show(getActivity().getFragmentManager(), "dialog"); 
        break; 
       } 
       default: 
        break; 
      } 
     } 
    }); 
    /* Creating initial fragment, containing the list view for all of the classes registered. */ 
    FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction(); 
    transaction.add(R.id.fragment, classFragment.newInstance()); 
    transaction.addToBackStack(null); 
    transaction.commit(); 
    setCurrentFragment(CLASS_LIST_VIEW); 

    return rootView; 
} 

@Override 
public void assignmentCallMethod(String pClass) { 
    /* A class was clicked. Changing the fragment to the assignment fragment. */ 
    currentClass = pClass; 
    FragmentTransaction transaction =getActivity().getSupportFragmentManager().beginTransaction(); 
    transaction.setCustomAnimations(R.anim.enter, R.anim.exit, R.anim.pop_enter, R.anim.pop_exit); 
    transaction.replace(R.id.fragment, assignmentsFragment.newInstance(pClass)); 
    transaction.addToBackStack(null); 
    transaction.commit(); 
    setCurrentFragment(ASSIGNMENT_LIST_VIEW); 
} 

/* Function that is called from the create class fragment. */ 
@Override 
public void createClicked() { 
    /* A new class was created. Recreating the class view fragment. */ 
    FragmentTransaction transaction =getActivity().getSupportFragmentManager().beginTransaction(); 
    transaction.setCustomAnimations(R.anim.pop_enter, R.anim.pop_exit, R.anim.enter, R.anim.exit); 
    transaction.replace(R.id.fragment, classFragment.newInstance()); 
    transaction.addToBackStack(null); 
    transaction.commit(); 
} 
@Override 
public void editClassMethod() { 
    /* A new class was edited. Recreating the class view fragment. */ 
    FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction(); 
    transaction.setCustomAnimations(R.anim.pop_enter, R.anim.pop_exit, R.anim.enter, R.anim.exit); 
    transaction.replace(R.id.fragment, classFragment.newInstance()); 
    transaction.addToBackStack(null); 
    transaction.commit(); 
} 



@Override 
public void editAssignmentMethod(int c) { 
    switch (c) { 
     case 0: 
      FragmentTransaction transaction =getActivity().getSupportFragmentManager().beginTransaction(); 
      transaction.setCustomAnimations(R.anim.enter, R.anim.exit, R.anim.pop_enter, R.anim.pop_exit); 
      transaction.replace(R.id.fragment, assignmentsFragment.newInstance(getParentClass())); 
      transaction.addToBackStack(null); 
      transaction.commit(); 
      break; 
     case 1: 
    } 
} 
// @Override 
public void onBackPressed() { 
    FragmentTransaction transaction; 
    switch (getCurrentFragment()) { 
     /* If viewing the class view, close the app. */ 
     case CLASS_LIST_VIEW: 
      getActivity().finish(); 
      return; 
     /* If viewing an assignment, return to the class view. */ 
     case ASSIGNMENT_LIST_VIEW: 
      transaction = getActivity().getSupportFragmentManager().beginTransaction(); 
      transaction.setCustomAnimations(R.anim.pop_enter, R.anim.pop_exit, R.anim.enter, R.anim.exit); 
      transaction.replace(R.id.fragment, classFragment.newInstance()); 
      transaction.addToBackStack(null); 
      transaction.commit(); 
      setCurrentFragment(CLASS_LIST_VIEW); 
      break; 
    } 
} 

} 
+0

允许抽象类就是这样,抽象的。他们不必遵循超级类/接口的严格指导原则。你在说你实现了onCreateActionListener,但是你并不是重写你的类中的方法,只要你真的使这个方法真实,你也不会声明你的方法摘要来超越这个需求。将'createAssignmentClicked(Assignment)'方法添加到您的类或摆脱接口声明。 – zgc7009

回答

1

这意味着,要实现接口CreateAssignmentDialogFragment,但你不能从这个接口覆盖方法onCreateInteractionListener(Assingment),为了使用,你必须重写方法的接口。

+0

工作!谢谢你 – PersianBlue

0

这个错误意味着如果你的片段实现了ColorDialogFragment.onCreateInteractionListener,它必须实现createAssignmentClicked(Assignment)。

相关问题