I am trying to pass the String [] items of my Dialog Fragment when the activity is running, as this String is updated and its values, which are showing the DialogFragment are updated and can not always choose the same.
I have read this topic: stackoverflow but I think that's not exactly what I need.
I know someone can help me?
This is my class DialogoSeleccion which extends DialogFragment:
public class DialogoSeleccion extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final String[] items = {"Español", "Inglés", "Francés"};
AlertDialog.Builder builder =
new AlertDialog.Builder(getActivity());
builder.setTitle("Selección")
.setMultiChoiceItems(items, null,
new DialogInterface.OnMultiChoiceClickListener() {
public void onClick(DialogInterface dialog, int item, boolean isChecked) {
Log.i("Dialogos", "Opción elegida: " + items[item]);
}
});
return builder.create();
}
}
And this is the code of the main class:
android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
DialogoSeleccion dialogo = new DialogoSeleccion();
dialogo.show(fragmentManager, "tagSeleccion");
I tried setting String[] items as a variable in the DialogoSeleccion class and then accessing it from the main method like this:
public class DialogoSeleccion extends DialogFragment {
private String[] opciones;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
...
String[] opciones = {"1","2"}
android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
DialogoSeleccion dialogo = new DialogoSeleccion();
dialogo.items= opciones[];
dialogo.show(fragmentManager, "tagSeleccion");
But it doesn't work.
Thanks for your help