Android的:如何使用NumberPickerDialog [英] Android: How to use NumberPickerDialog

查看:248
本文介绍了Android的:如何使用NumberPickerDialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能有人给我如何在Activity.onCreateDialog实例化一个NumberPickerDialog的例子吗?(<一href="https://github.com/novak/numberpicker/blob/master/lib/src/com/michaelnovakjr/numberpicker/NumberPickerDialog.java" rel="nofollow">https://github.com/novak/numberpicker/blob/master/lib/src/com/michaelnovakjr/numberpicker/NumberPickerDialog.java) ?

Could someone give me an example of how to instantiate a NumberPickerDialog within Activity.onCreateDialog ?(https://github.com/novak/numberpicker/blob/master/lib/src/com/michaelnovakjr/numberpicker/NumberPickerDialog.java) ?

有一个回购实例名为numberpicker,演示了使用小工具,但没有实际的对话框。

There are examples in a repo called numberpicker-demo for using the widget, but none for the actual dialog.

在其他的方法我已经试过想是这样:

Amongst other approaches I've tried tried something like:

return new NumberPickerDialog.Builder(this)
    .setTitle("Choose Number")
    .etc..

但是,这仅仅是一个标准AlertDialog,没有NumberPicker。

But this just shows a standard AlertDialog, without the NumberPicker.

谢谢!

推荐答案

得到它的工作最终。有一个在com.quietlycoding.android.picker.Picker一个例子,但是我发现,对话不设置调光正常,发黑了整个活动的背景,而它的视图。

Got it working eventually. There's an example in com.quietlycoding.android.picker.Picker, but I've found that the dialog doesn't set the dimming properly, blacking out the whole Activity in the background while it's in view.

我工作围绕这一简单地创建一个AlertDialog以通常的方式,然后只是坚持一个NumberPicker小部件到的setView():

I worked around this by simply creating an AlertDialog in the usual way, and then just sticking a NumberPicker widget into setView():

LayoutInflater inflater = (LayoutInflater)
    getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View npView = inflater.inflate(R.layout.number_picker_pref, 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();

请务必从numberpicker项目复制number_picker_ pref.xml水库/布局自己的项目。

Make sure to copy number_picker_pref.xml from the numberpicker project to res/layout in your own project.

这篇关于Android的:如何使用NumberPickerDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆