2016-04-13 2 views
-2

Ich bin neu in Android und ich habe versucht, dieses Bit Code, aber ich bekomme den folgenden Fehler: Fehler: (20 Fehler, 8): SyllabusFragment ist nicht abstrakt und enthebt nicht abstrakte Methode createAssignmentClicked (Assignment) in onCreateInteractionListenerAndroid Fehler: (20, 8) Fehler: Fragment ist nicht abstrakt und nicht abstrakte Methode

ich nicht in der Lage bin, was ist falsch mit meinem Code zu verstehen Jede Hilfe würde geschätzt

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

Abstrakte Klassen dürfen genau das sein, abstrakt. Sie müssen nicht den starren Richtlinien ihrer Superklasse/Schnittstellen folgen. Sie sagen, dass Sie onCreateActionListener implementieren, aber Sie überschreiben die Methode in Ihrer Klasse nicht an einer anderen Stelle, die dies tatsächlich wahr macht, noch deklarieren Sie Ihre Methodenzusammenfassung, um diese Anforderung zu umgehen. Fügen Sie Ihrer Klasse die Methode 'createAssignmentClicked (Assignment)' hinzu oder entfernen Sie die Interface-Deklaration. – zgc7009

Antwort

1

Es bedeutet, dass Sie die Schnittstelle CreateAssignmentDialogFragment implementieren, aber Sie sind nicht zwingende die Methode onCreateInteractionListener (assingment) von dieser Schnittstelle, um die Schnittstelle Sie diese Methode außer Kraft setzen müssen, um zu verwenden.

+0

Das hat funktioniert! Danke – PersianBlue

0

Der Fehler bedeutet, dass, wenn Ihr Fragment ColorDialogFragment.onCreateInteractionListener implementiert, createAssignmentClicked (Assignment) implementiert werden muss.

Verwandte Themen