开发者

Enable/Disable dialog buttons android

开发者 https://www.devze.com 2023-02-17 20:07 出处:网络
I have a dialogs which have one \"Text Box\" and Two buttons \"Continue and Cancel\". Conti开发者_JAVA百科nue button should be disable if we have empty text box and enabled otherwise.basically you nee

I have a dialogs which have one "Text Box" and Two buttons "Continue and Cancel". Conti开发者_JAVA百科nue button should be disable if we have empty text box and enabled otherwise.


basically you need textchange listener like this

etext.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            if(s.toString().equals("")
                               buttonContinue.setEnabled(false);
                        else
                               buttonContinue.setEnabled(true);

            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {


            }

            @Override
            public void afterTextChanged(Editable s) {


            }
        });


Inflate a layout and set it as the view for the dialog or alert dialog. Between inflating the view and setting it as the dialog view, you can set an ontextchangetedlistener.

0

精彩评论

暂无评论...
验证码 换一张
取 消