Create a custom dialog with radio buttons list

Atlas91 picture Atlas91 · Sep 11, 2015 · Viewed 58.6k times · Source

I've got a method in which i have a list of values:

     /**
     * ISO
     * */
    public void getISO(View view) {
        // Open dialog with radio buttons
        List<String> supported_isos = preview.getSupportedISOs();
        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
        String current_iso = sharedPreferences.getString(MainActivity.getISOPreferenceKey(), "auto");

    }

This method is enjected on onClick() of a ImageButton:

android:onClick="getISO"

But i need to rapresent this list in a dialog with radio buttons. Possibly the preference values should be already selected in the dialog.. Is it possible?

Answer

Abhisek picture Abhisek · Jun 2, 2016

best and easy way......

void dialog(){

        AlertDialog.Builder alt_bld = new AlertDialog.Builder(this);
        //alt_bld.setIcon(R.drawable.icon);
        alt_bld.setTitle("Select a Group Name");
        alt_bld.setSingleChoiceItems(grpname, -1, new DialogInterface
                .OnClickListener() {
            public void onClick(DialogInterface dialog, int item) {
                Toast.makeText(getApplicationContext(),
                        "Group Name = "+grpname[item], Toast.LENGTH_SHORT).show();
                dialog.dismiss();// dismiss the alertbox after chose option

            }
        });
        AlertDialog alert = alt_bld.create();
        alert.show();


///// grpname is a array where data is stored... 


    }