Fragment De Dialogue Personnalisée

Je suis en train de créer une simple boîte de dialogue similaire à un DatePickerDialog. Le Dialog que je suis en cours de création doit fournir à l'utilisateur avec un tableau d'images à partir de laquelle ils peuvent choisir.

Je crois que j'ai réussi à créer le tableau et ajouter les bonnes images, le problème, je suis en cours d'exécution dans maintenant est de savoir comment obtenir le Dialog à montrer? Que dois-je retourner?

J'ai regardé dans AlertDialogs et, mais je ne suis pas sûr de ce qu'il faut faire pour les mettre en œuvre.

MISE À JOUR: CORRECTION D'UN PROBLÈME DE CODE CI-DESSOUS FONCTIONNE

IMAGE SÉLECTEUR DE

public class PicturePickerFragment extends DialogFragment {

ArrayList<Integer> imageList = new ArrayList<Integer>();

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    //fill an array with selected images

    String title = "Picture";

    imageList.add(R.drawable.barbershop);
    imageList.add(R.drawable.wedding);
    imageList.add(R.drawable.meeting);
    imageList.add(R.drawable.barbershop);

    //return alertdialog
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    LayoutInflater inflater = getActivity().getLayoutInflater();

    //Inflate and set the layout for the dialog
    //Pass null as the parent view because its going in the dialog layout
    builder.setView(inflater.inflate(R.layout.activity_create, null))
            .setTitle(R.string.event_type)
            .setPositiveButton(R.string.select_picture,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog,
                                int which) {
                            //call the method on the parent activity when
                            //user click the positive button
                        }
                    });
    return builder.create();
}

}

DE RÉFÉRENCE

public class DatePickerFragment extends DialogFragment implements
    DatePickerDialog.OnDateSetListener {

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    //Use the current date as the default date in the picker
    final Calendar c = Calendar.getInstance();
    int year = c.get(Calendar.YEAR);
    int month = c.get(Calendar.MONTH);
    int day = c.get(Calendar.DAY_OF_MONTH);

    //Create a new instance of DatePickerDialog and return it
    return new DatePickerDialog(getActivity(), this, year, month, day);
}

public void onDateSet(DatePicker view, int year, int month, int day) {
    //Do something with the date chosen by the user
    month++;
    String dateString = month + "/" + day + "/" + year;
    Button b = (Button) getActivity().findViewById(R.id.btn_date);
    b.setText(dateString);
}
}

LE FRAGMENT SERA UTILISÉ COMME CELA

<Button
    android:id="@+id/btn_picture"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_marginBottom="15dp"
    android:layout_marginTop="15dp"
    android:layout_weight="1"
    android:background="@null"
    android:drawablePadding="15dp"
    android:onClick="showPicturePickerDialog"
    android:drawableTop="@drawable/ico_picture"
    android:text="Picture"
    android:textColor="@color/darkbrown"
    android:textSize="20sp" />
pls consulter developer.android.com/reference/android/app/DialogFragment.html ce lien et faites google avant de poster la question

OriginalL'auteur Coova | 2014-03-06