【问题标题】:How to display more numbers in NumberPicker while scrolling滚动时如何在 NumberPicker 中显示更多数字
【发布时间】:2019-07-07 01:44:39
【问题描述】:

如何在滚动时在数字选择器中显示更多项目/数字,因为它只显示 3 个数字。这是我的代码

 NumberPicker starttime = (NumberPicker) findViewById(R.id.timeListview);

    starttime.setMaxValue(47);
    String[] time = {"12:00 AM", "12:30 AM", "01:00 AM", "01:30 AM", "02:00 AM", "02:30 AM", "03:00 AM","11:00 PM", "11:30 PM"};
    starttime.setDisplayedValues(time);
    starttime.setWrapSelectorWheel(true);

【问题讨论】:

  • 我认为这对于 Native NumberPicker 小部件是不可能的。
  • 可以试试,numberPicker.setWheelItemCount(5)
  • @ADM 你知道在不使用 NumberPicker 的情况下如何在滚动时显示更多元素并使中间元素聚焦的其他方法吗?
  • @Hasanuzzaman Rana 它不工作
  • 如果可以的话,你可以使用第三方库 Like This one 我在第一次搜索时找到的。

标签: android numberpicker


【解决方案1】:

我已经更改了你的代码,请试试这个,它会有所帮助

NumberPicker starttime = findViewById(R.id.timeListview);
String[] time = {"12:00 AM", "12:30 AM", "01:00 AM", "01:30 AM", "02:00 AM", "02:30 AM", "03:00 AM","11:00 PM", "11:30 PM"};
    starttime.setMinValue(0);
    starttime.setMaxValue(time.length-1);
    starttime.setDisplayedValues(time);
    starttime.setWrapSelectorWheel(true);

【讨论】:

  • 我使用了你修改过的代码,它不起作用,只显示 3 个项目
  • @partival 您需要分享更多代码,Sandeep 解决方案是一个很好的解决方案,请参阅my answer here 以查看它是否有效。如果此解决方案有效,您还有其他问题 - 但是我们需要代码来帮助您
猜你喜欢
  • 2018-09-22
  • 2014-08-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-19
  • 1970-01-01
  • 2019-01-05
相关资源
最近更新 更多