Android NumberPicker 对 Gingerbread 的限制 [英] Android NumberPicker limits on Gingerbread

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

问题描述

我有一个数字选择器:

  AlertDialog alertDialog = builder.create();
  alertDialog.setTitle("Quantidade");
  NumberPicker NP = (NumberPicker)view.findViewById(R.id.npicker);
  NP.setMaxValue(1000);
  NP.setMinValue(1);
  alertDialog.setButton(...);
  alertDialog.show();

这在 Android 4.0.x 上运行良好,但在 Android 2.3.x 上我得到

This works fine on Android 4.0.x, but on Android 2.3.x I get

java.lang.NoSuchMethodError: android.widget.NumberPicker.setMaxValue

如果我删除 NP.setMaxValue(1000)NP.setMinValue(1),它可以工作但限制设置为 0,有什么方法可以设置Android 2.3.x 上的数字选择器限制?

If I remove NP.setMaxValue(1000) and NP.setMinValue(1), it works but the limits are set as 0, is there any way to set the number picker limits on Android 2.3.x?

推荐答案

根据文档,NumberPicker(及其所有方法)仅在 API 级别 11 (SDK 3.0) 中可用.所以如果你想与 2.3.x 兼容,你需要有自己的实现.幸运的是,这里

As per the documentation, NumberPicker (and all its methods) are available only from API Level 11 (SDK 3.0). So if you want compatibility with 2.3.x, you need to have your own implementation. Luckily there is one already available here

编辑

互联网对上面的链接不太友好,不再可用.甚至评论中建议的替代方案也没有了.你最好自己写.

The Internet has been not so gentle on the link above and it is no longer available. Even the alternatives suggested in the comments are also gone. You are better off writing your own.

这篇关于Android NumberPicker 对 Gingerbread 的限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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