I have a code where I created a method to display a dialog box with the option of multi-choice but when checking and clicking the OK button the status is not saved how can I do this? I saw something with sharedpreferences but I'm not able to implement it in my code could someone help me?
public View onCreateView(final LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_inseticida, container, false);
gps = view.findViewById(R.id.imageButton);
gps.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showAlertDialog();
}
});
private void showAlertDialog (){
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Habilitar GPS");
String[] Gps = new String[]{
"Habilitar GPS",
};
// Boolean array for initial selected items
final boolean[] checkedgps = new boolean[]{
true, // GPS
};
// Convert the color array to list
final List<String> gpsList = Arrays.asList(Gps);
builder.setMultiChoiceItems(Gps, checkedgps, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i, boolean b) {
checkedgps[i] = b;
String CurrentItem = gpsList.get(i);
Toast.makeText(getActivity(),CurrentItem + " " + b,Toast.LENGTH_SHORT).show();
}
});
builder.setCancelable(false);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
AlertDialog dialog = builder.create();
// Display the alert dialog on interface
dialog.show();
}