Question

I am learning to use DialogFragments


In my main activity in a condition i have

MyAlertDialogFragment alert = new MyAlertDialogFragment();
alert.show(getFragmentManager(), "Alert_Dialog");

MyAlertDialogFragment.java

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Typeface;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.util.Log;
import android.widget.TextView;
import android.support.v4.app.DialogFragment;
import com.example.findmybuffet.R;
    public class MyAlertDialogFragment extends DialogFragment {

        @Override
         public Dialog onCreateDialog(Bundle savedInstanceState) {

          OnClickListener positiveClick = new OnClickListener() {   
           @Override
           public void onClick(DialogInterface dialog, int which) {    
            Toast.makeText(getActivity().getBaseContext(), "Application finishing ...", Toast.LENGTH_SHORT).show();
            getActivity().finish();    
           }
          };

          OnClickListener negativeClick = new OnClickListener() {   
           @Override
           public void onClick(DialogInterface dialog, int which) {
            Toast.makeText(getActivity().getBaseContext(), "No option selecting", Toast.LENGTH_SHORT).show();

           }
          };

          AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
          builder.setMessage("Do you want Yes or No ?");
          builder.setNegativeButton("No", negativeClick);
          builder.setPositiveButton("Yes", positiveClick);
          builder.setTitle("Confirmation");
          Dialog dialog = builder.create();
          return dialog;
         }
    }

my problem::

  • In the line alert.show(getFragmentManager(), "Alert_Dialog");
  • I am getting error as The method show(FragmentManager, String) in the type DialogFragment is not applicable for the arguments (FragmentManager, String)
  • How to resolve this so that i am able to pop the fragment
Was it helpful?

Solution

As you're using android.support.v4.app.DialogFragment, you should pass to show() an instance of android.support.v4.app.FragmentManager which can be queried using an getSupportFragmentManager() call instead of getFragmentManager().

OTHER TIPS

Replace getFragmentManager() with getSupportFragmentManager().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top