从甜蜜警报对话框Android中删除“确定”按钮

时间:2017-02-25 10:08:14

标签: android android-alertdialog

我正在使用SweetAlert Dialog for android。

https://github.com/pedant/sweet-alert-dialog

在成功对话框中,我想删除OK按钮,因为我正在使用计时器选项,但是在他们的文档中没有提到这样做的选项。请解释如何删除确定按钮。

enter image description here

MainActivity.java

public class Main2Activity extends AppCompatActivity {
private Firebase mRootRef;
private Button mBtn1;
private Button mBtn2;
int counter;
int counter1;
long value;



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main2);
    Firebase.setAndroidContext(this);
    mBtn1 = (Button) findViewById(R.id.btn1);
    mBtn2 = (Button) findViewById(R.id.btn2);
    mBtn1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (v.equals(mBtn1)) {
                mRootRef = new Firebase("https://voting-cf0fa.firebaseio.com/House/Jupiter/Player 1");
                final Firebase mRefChild = mRootRef.child("Votes");
                mRefChild.runTransaction(new Transaction.Handler() {
                    @Override
                    public Transaction.Result doTransaction(final MutableData currentData) {
                        if (currentData.getValue() == null) {
                            currentData.setValue(1);
                        } else {
                            currentData.setValue((Long) currentData.getValue() + 1);
                        }
                        return Transaction.success(currentData);
                    }

                    public void onComplete(FirebaseError firebaseError, boolean committed, DataSnapshot currentData) {
                    }
                });
                MediaPlayer click1 =MediaPlayer.create(getApplicationContext(), R.raw.click);
                click1.start();
                mBtn1.setEnabled(false);
                mBtn2.setEnabled(false);
                Timer buttonTimer = new Timer();
                buttonTimer.schedule(new TimerTask() {

                    @Override
                    public void run() {
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                mBtn1.setEnabled(true);
                                mBtn2.setEnabled(true);
                            }
                        });
                    }
                }, 5000);
                final  SweetAlertDialog Voted = new SweetAlertDialog(Main2Activity.this, SweetAlertDialog.SUCCESS_TYPE);
                Voted.setTitleText("Voted");
                Voted.setContentText("You Have cast your Vote!");
                Voted.show();
                Voted.findViewById(R.id.confirm_button).setVisibility(View.GONE);

                final Timer t = new Timer();
                t.schedule(new TimerTask() {
                    @Override
                    public void run() {
                       Voted.dismiss();
                        t.cancel();
                    }
                }, 5000);

            }

        }
    });


    mBtn2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mRootRef = new Firebase("https://voting-cf0fa.firebaseio.com/House/Jupiter/Player 2");
            if (v.equals(mBtn2)) {
                Firebase mRefChild = mRootRef.child("Votes");
                mRefChild.runTransaction(new Transaction.Handler() {
                    @Override
                    public Transaction.Result doTransaction(final MutableData currentData) {
                        if (currentData.getValue() == null) {
                            currentData.setValue(1);
                        } else {
                            currentData.setValue((Long) currentData.getValue() + 1);
                        }
                        return Transaction.success(currentData);
                    }

                    public void onComplete(FirebaseError firebaseError, boolean committed, DataSnapshot currentData) {
                    }
                });
                MediaPlayer click2 =MediaPlayer.create(getApplicationContext(), R.raw.click);
                click2.start();
                mBtn2.setEnabled(false);
                mBtn1.setEnabled(false);
                Timer buttonTimer = new Timer();
                buttonTimer.schedule(new TimerTask() {

                    @Override
                    public void run() {
                        runOnUiThread(new Runnable() {

                            @Override
                            public void run() {
                                mBtn2.setEnabled(true);
                                mBtn1.setEnabled(true);
                            }
                        });
                    }
                }, 5000);
                final  SweetAlertDialog Voted = new SweetAlertDialog(Main2Activity.this, SweetAlertDialog.SUCCESS_TYPE);
                Voted.setTitleText("Voted");
                Voted.setContentText("You Have cast your Vote!");
                Voted.show();
                Voted.findViewById(R.id.confirm_button).setVisibility(View.GONE);

                final Timer t = new Timer();
                t.schedule(new TimerTask() {
                    @Override
                    public void run() {
                        Voted.dismiss();
                        t.cancel();
                    }
                }, 5000);

            }
            }
        });
    }
@Override
public void onBackPressed() { }

}

3 个答案:

答案 0 :(得分:6)

我假设您的代码看起来像

new SweetAlertDialog(this, SweetAlertDialog.SUCCESS_TYPE)
    .setTitleText("Good job!")
    .setContentText("You clicked the button!")
    .show();

所以答案是

SweetAlertDialog dialog = new SweetAlertDialog(this, SweetAlertDialog.SUCCESS_TYPE)
    .setTitleText("Good job!")
    .setContentText("You clicked the button!")
    .show();

dialog.findViewById(R.id.confirm_button).setVisibility(View.GONE);

答案 1 :(得分:0)

这也有效

SweetAlertDialog sweetdialog = new SweetAlertDialog(this, SweetAlertDialog.SUCCESS_TYPE)
.setTitleText("Good job!")
.setContentText("You clicked the button!")
.show();

 sweetdialog.getButton(SweetAlertDialog.BUTTON_CONFIRM).setVisibility(View.GONE);

答案 2 :(得分:0)

OVER (ORDER BY created desc ROWS BETWEEN CURRENT ROW AND 49 FOLLOWING ROW)