【问题标题】:Android: How to set max to min values of numberpicker with offset of 10Android:如何将数字选择器的最大值设置为最小值,偏移量为 10
【发布时间】:2017-11-14 20:54:52
【问题描述】:

我想要数值为 10,20,30,40,50 的数字选择器 当我这样做时:

    minutePicker.setMaxValue(10);
    minutePicker.setMinValue(1);
    minutePicker.setDisplayedValues(values);

提供的值为 {"30", "40", "50", "60", "70"};

我能够按预期显示值,但这些就像编辑文本,当我点击每个值键盘显示时,我怎样才能让它只显示值作为 textview 而不是编辑文本

【问题讨论】:

  • 是的,但它是可编辑的,我怎样才能禁用可编辑
  • android:descendantFocusability="blocksDescendants",将禁用 numberpicker 上的软键盘,这将删除为 NumberPicker 输入值的能力
  • 在哪里可以看到可以在 xml 上使用的属性
  • 我怎样才能删除分隔线
  • 您需要使用反射。查看此 stackoverflow 帖子以获取更多详细信息:stackoverflow.com/questions/24233556/…

标签: java android numberpicker android-number-picker


【解决方案1】:

如下创建 NumberPicker 类

public class MyNumberPicker extends NumberPicker {

public MyNumberPicker(Context context, AttributeSet attrs) {
    super(context, attrs);
    processAttributeSet(attrs);
}

public MyNumberPicker(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    processAttributeSet(attrs);
}
private void processAttributeSet(AttributeSet attrs) {
    //This method reads the parameters given in the xml file and sets the properties according to it
    this.setMinValue(attrs.getAttributeIntValue(null, "min", 0));
    this.setMaxValue(attrs.getAttributeIntValue(null, "max", 0));
}

}

【讨论】:

  • 能否详细说明,我想删除分隔线
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-09-27
相关资源
最近更新 更多