是否有在Android中输入查询整数的看法?整数、看法、Android

2023-09-12 04:07:58 作者:の把手交给我

我在寻找类似的日期选取器对话框的各个部分。视图,使您可以输入整数(只有整数),您可以限制(1到10之间为例),在那里你可以使用键盘或在视图本身的箭头。它是否存在?

I'm looking for something like the individual parts of the date picker dialog. A view that allows you to input integers (and only integers) that you can limit (between 1 and 10 for example), where you can use the keyboard or the arrows in the view itself. Does it exists?

有针对对话。一个现成的对话框,要求一个整数也会有所帮助。

It is for a dialog. A ready-made dialog to request an integer would also help.

推荐答案

该NumberPicker部件可能是你想要的东西。不幸的是它位于com.android.internal.Widget.NumberPicker我们不能得到通过正常的手段。

The NumberPicker widget is probably what you want. Unfortunatly it's located in com.android.internal.Widget.NumberPicker which we cannot get to through normal means.

有两种使用它的方式:

从Android源复制code 使用反射来访问的小部件

下面是XML的布局中使用它:

Here's the xml for using it in a layout:

<com.android.internal.widget.NumberPicker
    android:id="@+id/picker"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

这里的反射来设置NumberPicker设置(我没有测试过这一点):

Here's the reflection to set the NumberPicker settings (I have not tested this):

Object o = findViewById(R.id.picker);
Class c = o.getClass();
try 
{
    Method m = c.getMethod("setRange", int.class, int.class);
    m.invoke(o, 0, 9);
} 
catch (Exception e) 
{
    Log.e("", e.getMessage());
}

由于它是一个内部小部件,而不是在SDK,未来的兼容性可能是,如果你使用反射打破。这将是最安全的推出自己的从源头。

Since it's an internal widget and not in the SDK, future compatibility could be broken if you use reflection. It would be safest to roll your own from the source.

此情报的原始来源是在这里:

The original source for this informaiton is here:

http://groups.google.com/group/android-developers/browse_frm/thread/65da9820998fddc9/6151cc9800e6a04d#6151cc9800e6a04d