Imansible risolvere il metodo 'show (android.support.v4.app.FragmentManager, java.lang.String)

Per qualche ragione quando cerco di mostrare un dialogo ottengo un errore da dialog.show (fm, DIALOG_DATE); dicendo che non riesce a risolvere il metodo 'show (android.support.v4.app.FragmentManager, java.lang.String)'

Perché non è ansible risolvere il metodo?

  • Mostra una sovrapposizione "help" su un layout Android
  • Dagger + Proguard obfuscation, Errori che creano un grafico di oggetti
  • Applicare molti filtri di colore allo stesso disegnatore
  • Sync di progetto di Android Gradle non riuscito a causa della versione di destinazione
  • Creare getFilter per BaseAdapter per i titoli Object?
  • esplorare i dati nel database Android SQLite
  • mDateButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { FragmentManager fm = getActivity().getSupportFragmentManager(); DatePickerFragment dialog = new DatePickerFragment(); dialog.show(fm, DIALOG_DATE); } }); 

    Ecco il resto della mia class:

     package com.bignerdranch.android.criminalintent; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.text.Editable; import android.text.TextWatcher; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.CheckBox; import android.widget.Button; import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.EditText; import java.util.UUID; public class CrimeFragment extends Fragment { //key for the extra public static final String EXTRA_CRIME_ID = "com.bignerdranch.android.criminalintent.crime_id"; private static final String DIALOG_DATE = "date"; //holds crime private Crime mCrime; //widgets private EditText mTitleField; private Button mDateButton; private CheckBox mSolvedCheckBox; //at start of build @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //get crime from crime class /*Intents *There are two ways a fragment can access data in its activity's intent: * an easy direct shortcut * or a complex flexible implementation * First try out the shortcut * in the shortcut, CrimeFragment will access CrimeActivity's intent directly */ //retrieve the extra from CrimeActivity's intent and use it to fetch the Crime //UUID crimeId = (UUID)getActivity().getIntent().getSerializableExtra (EXTRA_CRIME_ID); //shortcut removed in chapter 10 and "should feel warm and fuzzy inside for maintaining CrimeFragments Independence" // UUID crimeId = (UUID)getArguments().getSerializable(EXTRA_CRIME_ID); //CrimeLab.get() requires a context object, so CrimeFragment passes the CrimeActivity mCrime = CrimeLab.get(getActivity()).getCrime(crimeId); } //Create the view and inflate the layout @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for crime Fragment //pass false because view will be added in the activitys code View v = inflater.inflate(R.layout.fragment_crime, container, false); //gets crime_title from fragment_crime.xml mTitleField = (EditText)v.findViewById(R.id.crime_title); mTitleField.setText(mCrime.getTitle()); mTitleField.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { //not used } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { mCrime.setTitle(s.toString()); } @Override public void afterTextChanged(Editable s) { //also not used } }); //find date button from fragment_crime mDateButton = (Button)v.findViewById(R.id.crime_date); //set mDateButton text to current date and time mDateButton.setText(mCrime.getDate().toString()); //disable button for now...enabled in chapter 12 // mDateButton.setEnabled(false); mDateButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { FragmentManager fm = getActivity().getSupportFragmentManager(); DatePickerFragment dialog = new DatePickerFragment(); dialog.show(fm, DIALOG_DATE); } }); //find solved checkbox from fragment_crime mSolvedCheckBox = (CheckBox)v.findViewById(R.id.crime_solved); mSolvedCheckBox.setChecked(mCrime.isSolved()); //user clicks solved check box mSolvedCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked){ //set the crime's solved property mCrime.setSolved(isChecked); } }); //returns the view return v; } /*The downside to direct retrieval *can not encapsulate fragment * CrimeFragment is no longer a reusable building block because it expects that it will always be hosted by an activity whose intent defines extra named "EXTRA_CRIME_ID" * CrimeFragment cannot be used with just any activity * */ /*Fragment Arguments *A better solution is to stash the mCrimeId someplace that belongs to CrimeFragment rather than keeping it in CrimeActivity's personal space * this someplace can be an arguments bundle * Every fragment instance can have a Bundle object attached to it * bundle contains key value pairs that work just like the intent extras of an activity * Pg. 195 */ /*attaching arguments to a fragment *Attaching args to frags must be done after the frag is created but before it is added to the activity * To hit this window use a static class called newInstance() * This method creates the fragment instance and bundles up and sets its arguments */ //for attaching arguments to a fragment public static CrimeFragment newInstance(UUID crimeId){ Bundle args = new Bundle(); args.putSerializable(EXTRA_CRIME_ID, crimeId); CrimeFragment fragment = new CrimeFragment(); fragment.setArguments(args); //pass UUID from extra return fragment; } 

    }

  • Google Drive Android API (GDAA) getResourceId () restituisce null (timing issue)
  • onKeyDown e onKeyLongPress
  • Twitter PostActivity issue
  • Come rimuovere i pulsanti zoom sul webview di Android?
  • java.lang.IllegalStateException: È necessario utilizzare un tema Theme (o descendente) di Theme.AppCompat con questa attività. titanio
  • Aggiornamento dell'interface utente da un servizio (utilizzando un gestore?)
  • One Solution collect form web for “Imansible risolvere il metodo 'show (android.support.v4.app.FragmentManager, java.lang.String)”

    Per risolvere questo problema, se utilizzi android.app.DialogFragment , utilizza: getFragmentManager()

     mDateButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { FragmentManager fm = getActivity().getFragmentManager(); DatePickerFragment dialog = new DatePickerFragment(); dialog.show(fm, DIALOG_DATE); } }); 

    per utilizzare getSupportFragmentManager() , DatePickerFragment() deve estendersi da: android.support.v4.app.DialogFragment

    controlla l'importzione:

     import android.support.v4.app.DialogFragment; 
    L'Android è un fan Android di Google, tutto su telefoni Android, Android Wear, Android Dev e applicazioni Android Games e così via.