-1

I have a layout with a button.

The layout

The onclick shows an AlertDialog, with the options Ok and Cancel. I want that if one clicks on the "Ok", the button in the layout disappears.

Here's my code so far:

In the main, I have this function:

public void requestCheckButton(View view) {
    RequestAccepted ra = new RequestAccepted(this);
}

The RequestAccepted function:

public class RequestAccepted {
Context context;

public RequestAccepted(final Context context){
    this.context = context;

    final AlertDialog.Builder popDialog = new AlertDialog.Builder(context);
    final SeekBar seek = new SeekBar(context);
    seek.setMax(11); // Para tener incrementos de 5 min
    seek.setProgress(1);

    popDialog.setTitle("¿En cuánto tiempo puedes llegar?");
    popDialog.setMessage("5 min");
    popDialog.setView(seek);
    popDialog.setPositiveButton("Mandar", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Toast.makeText(context, "Presionaste Mandar", Toast.LENGTH_SHORT).show();

        }
    });

    final AlertDialog dialog = popDialog.create();
    seek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        int progress = 1;

        public void onProgressChanged(SeekBar seekBar, int progressV, boolean fromUser) {
            progress = progressV;
        }

        public void onStartTrackingTouch(SeekBar arg0) {

        }

        public void onStopTrackingTouch(SeekBar seekBar) {
            //Por cada incremento se suman 5 min
            dialog.setMessage((progress)*5 +" min");
        }
    });
    dialog.show();
}
Hussein El Feky
  • 6,627
  • 5
  • 44
  • 57
Alxlly
  • 61
  • 1
  • 10

1 Answers1

1

Add Button button as a parameter in RequestAccepted class:

public RequestAccepted(final Context context, final Button button) {
    ...
}

Modify this in your onClickListener of ok button in the dialog:

popDialog.setPositiveButton("Mandar", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Toast.makeText(context, "Presionaste Mandar", Toast.LENGTH_SHORT).show();
            button.setVisibility(View.GONE);
        }
    });

Now call this class from any activity you want as follows:

public void requestCheckButton(View view){
    RequestAccepted ra = new RequestAccepted(this, button);
}

where button is the button that you want to set its visibility to gone.

Hussein El Feky
  • 6,627
  • 5
  • 44
  • 57