我是Android的新手,我一直在尝试这段代码但是我收到以下错误: 错误:(20,8)错误:SyllabusFragment不是抽象的,并且不会覆盖onCreateInteractionListener中的抽象方法createAssignmentClicked(Assignment)
我无法理解我的代码有什么问题 任何帮助将不胜感激
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 :(得分:1)
这意味着您正在实现界面 CreateAssignmentDialogFragment ,但您没有从此界面覆盖 onCreateInteractionListener(Assingment)方法,以便使用您必须使用的界面覆盖该方法。
答案 1 :(得分:0)
错误意味着如果你的片段实现ColorDialogFragment.onCreateInteractionListener,它必须实现createAssignmentClicked(赋值)。