简体   繁体   中英

Android support library v4 dialog fragment

What I am trying to do ? I have got this fragment which loads up an xml. within that xml I have an image button and it should display a dialog message.

This is the code for the fragment ;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class LoadingupFragment extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    final View v = inflater.inflate(R.layout.example, container, false);

 return v;
}


public void dialogboxalert (View view){

    ExampleAlert dialog = new ExampleAlert();
   // dialog.show(getSupportFragmentManager(),""); ERRRORRR

}

This is the code for the dialog ;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;

public class ExampleAlert extends android.support.v4.app.DialogFragment {

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {

        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setMessage("This is my dialog..").setPositiveButton("OK",new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

            }
        }).setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

            }
        });

        AlertDialog dialog = builder.create();

        return dialog;
    }
}

Please can someone help me with the support library issue ??

发生此问题是因为您的DialogFragment扩展了android.app.DialogFragement并且它应该扩展了android.support.v4.app.DialogFragment

Since Google released new support library, you should extend your dialog fragment using this class AppCompatDialog

https://developer.android.com/reference/android/support/v7/app/AppCompatDialog.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM