Using NumberPicker Widget with Strings

后端 未结 5 440
情歌与酒
情歌与酒 2020-11-30 18:58

Is there a way to use the Android NumberPicker widget for choosing strings instead of integers?

5条回答
  •  执念已碎
    2020-11-30 19:52

    NumberPicker numberPicker = new NumberPicker(this);
    String[] arrayString= new String[]{"hakuna","matata","timon","and","pumba"};
    numberPicker.setMinValue(0);
    numberPicker.setMaxValue(arrayString.length-1);
    
    numberPicker.setFormatter(new NumberPicker.Formatter() {
      @Override
      public String format(int value) {
        // TODO Auto-generated method stub
        return arrayString[value];
      }
    });
    

    hope that helps!

提交回复
热议问题