jeudi 30 juin 2016

What is the good way to create alertdialog with checkbox and seekbar in android?

How to create alert dialogs with or without xml as per image below ? sample code will help.

  1. Seekbar is disabled when checkbox is checked.

alertDialog with checkbox and seekbar

For this dialog, I was able to create some short of dialog but, I am not sure how to place check box and its logic if checkbox is checked/uncheckd, seekbar needs to disabled/enabled.

public void ShowDialog()
{
    final AlertDialog.Builder popDialog = new AlertDialog.Builder(this);
    popDialog.setPositiveButton("OK",
    new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    popDialog.setNegativeButton("Cancel",
    new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    final SeekBar seek = new SeekBar(this);
    seek.setMax( ... );
    seek.setProgress(...);
    final AlertDialog handle = popDialog.create();

    handle.setIcon(android.R.drawable.ic_menu_preferences);     
    handle.setTitle("Brighness"); 
    handle.setView(seek);

    seek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser){
            //Log.d(TAG, "Value of : " + value);
        }

        public void onStartTrackingTouch(SeekBar arg0) {
            //Log.d(TAG, "onStartTrackingTouch");
        }

        public void onStopTrackingTouch(SeekBar seekBar) {
            //Log.d(TAG, "onStopTrackingTouch");
        }
    });
    handle.show();      
}
  1. Auto line is dimmed when seekbar is highlighted.

Auto dimmed, seekbar highlighted

  1. seekbar is dimmed when Auto line is highlighted.

Auto highlighted, seekbar dimmed

I have checked other questions, those are more about custom dialogs : How to create a Custom Dialog box in android? But, None of these are giving me clear idea so, I am asking this specific question.

Aucun commentaire:

Enregistrer un commentaire