I am trying to call DialogFragment from my Fragment class. I have an ImageView, and I would like to name my DialogFragment class in onClickListener from the ImageView that I created.
I get an error in onClick with the code that I configured while trying to call DialogFragment.
I get an error "show": "Show method (FragmentManager, String) in type DialogFragment is not applicable for arguments (FragmentManager, String)" and an error in "new instance" indicating "Method newInstance () is undefined for type MyDialogFragment"
Here is my code:
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View v = inflater.inflate(R.layout.image_detail_fragment, container, false); mImageView = (RecyclingImageView) v.findViewById(R.id.imageView); mImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) {
DialogFragment Class:
import android.app.AlertDialog; import android.app.Dialog; import android.app.DialogFragment; import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; class MyDialogFragment extends DialogFragment { Context mContext; public MyDialogFragment() { mContext = getActivity(); } @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext); alertDialogBuilder.setTitle("Set Wallpaper?"); alertDialogBuilder.setMessage("Are you sure?");
source share