Number picker dialog [closed]

感情迁移 提交于 2019-12-28 11:53:46

问题


Does anyone know where can I find a tutorial or example on how to achive this kind of number picker dialog on android? I googled everything but only managed to find examples where you have to create your own buttons with custom images etc. Can this be done in simple way?

All I could find was this: http://www.quietlycoding.com/?p=5 but it doesn't quite help me.


回答1:


If you are targeting API level 11 or higher, you can use NumberPicker

If you are targeting earlier API levels, you will have to write your own NumberPicker or use one from a third party library.

Here is a nice video tutorial.

Good luck!




回答2:


The easiest way you can go with this is to use default Android NumberPicker.

The way to design it like you want is to create your custom dialog and embed one of those in it such as:

LayoutInflater inflater = (LayoutInflater)
    getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View npView = inflater.inflate(R.layout.number_picker_dialog_layout, null);
    return new AlertDialog.Builder(this)
        .setTitle("Text Size:")
        .setView(npView)
        .setPositiveButton(R.string.dialog_ok,
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {

                }
            })
            .setNegativeButton(R.string.dialog_cancel,
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                    }
                })
            .create();


来源:https://stackoverflow.com/questions/11800589/number-picker-dialog

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!