单击对话框按钮后设置按钮的可见性

Set visibility of a button after clicking on a Dialog button

我有一个带按钮的布局。

onclick 显示一个 AlertDialog,带有 Ok 和 Cancel 选项。我希望如果单击 "Ok",布局中的按钮就会消失。

到目前为止,这是我的代码:

主要是我有这个功能:

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

RequestAccepted 函数:

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();
}

在 RequestAccepted 中添加 Button button 作为参数 class:

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

在对话框中确定按钮的 onClickListener 中修改:

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);
        }
    });

现在从您想要的任何 activity 调用此 class,如下所示:

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

其中 button 是您要将其可见性设置为消失的按钮。