Android 号码选择器对话框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11800589/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 08:54:42  来源:igfitidea点击:

Number picker dialog

androidwidget

提问by Rohit Malish

enter image description here

在此处输入图片说明

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?

有谁知道我在哪里可以找到有关如何在 android 上实现这种数字选择器对话框的教程或示例?我用谷歌搜索了所有东西,但只找到了一些例子,你必须用自定义图像等创建自己的按钮。这可以用简单的方式完成吗?

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

我能找到的只有这个:http: //www.quietlycoding.com/?p=5但这对我并没有多大帮助。

采纳答案by Zambotron

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

如果您的目标是 API 级别 11 或更高,则可以使用NumberPicker

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

如果您的目标是较早的 API 级别,则必须编写自己的 NumberPicker 或使用第三方库中的一个。

Hereis a nice video tutorial.

是一个很好的视频教程。

Good luck!

祝你好运!

回答by Erol

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

最简单的方法是使用默认的 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();