开发者

Enable/Disable dialog buttons android

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜