Skip to content

A proxy of Android AlertDialog providing input and validation features based on EditText.

Notifications You must be signed in to change notification settings

Cookizz/InputDialog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 

Repository files navigation

InputDialog

A proxy of AlertDialog for Android that provides input and validation features.

Appearance

demo

Use Case

  • Put InputDialog into your project and put dialog_input_layout.xml, dialog_bottom_line.9.png into your resource folder and use InputDialog in the way just like AlertDialog.
new InputDialog.Builder(context)
        .setTitle("新建文件夹")
        .setInputDefaultText("/sdcard/my")
        .setInputMaxWords(20)
        .setInputHint("文件夹路径")
        .setPositiveButton("确定", new InputDialog.ButtonActionListener() {
            @Override
            public void onClick(CharSequence inputText) {
                // TODO
            }
        })
        .setNegativeButton("取消", new InputDialog.ButtonActionListener() {
            @Override
            public void onClick(CharSequence inputText) {
                // TODO
            }
        })
        .setOnCancelListener(new InputDialog.OnCancelListener() {
            @Override
            public void onCancel(CharSequence inputText) {
                // TODO
            }
        })
        .interceptButtonAction(new InputDialog.ButtonActionIntercepter() { // 拦截按钮行为
            @Override
            public boolean onInterceptButtonAction(int whichButton, CharSequence inputText) {
                if ("/sdcard/my".equals(inputText) && whichButton == DialogInterface.BUTTON_POSITIVE) {
                    // TODO 此文件夹已存在,在此做相应的提示处理
                    // 以及return true拦截此按钮默认行为
                    return true;
                }
                return false;
            }
        })
        .show();

Advanced

  • Customize your layout

Call build method setView(int layoutResId, int editTextId) to apply your own EditText appearance. The second parameter instructs you to bind your target EditText by id.

new InputDialog.Builder(context)
        .setView(R.layout.my_edit_text, R.id.my_edit_text)
  • Apply input validation

Sometimes you are unwilling to dismiss your dialog after clicking its buttons. Instead, you may need an input validation to intercept the inherent dismiss behavior.

Just call build method interceptButtonAction(ButtonActionIntercepter intercepter) to catch illegal input and do whatever you want.

new InputDialog.Builder(context)
        .interceptButtonAction(new InputDialog.ButtonActionIntercepter() { // 拦截按钮默认行为
            @Override
            public boolean onInterceptButtonAction(int whichButton, CharSequence inputText) {
                if ("/sdcard/my".equals(inputText) && whichButton == DialogInterface.BUTTON_POSITIVE) {
                    // TODO 此文件夹已存在,在此做相应的提示处理
                    // 以及return true拦截此按钮默认行为
                    return true;
                }
                return false;
            }
        })

About

A proxy of Android AlertDialog providing input and validation features based on EditText.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages