Using NumberPicker Widget with Strings

后端 未结 5 436
情歌与酒
情歌与酒 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:38

    This worked for me.

    public class YourClassName extends AppCompatActivity {
    
    NumberPicker picker = null;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.your_activity_layout_file);
    
        picker = (NumberPicker) findViewById(R.id.pickerId_From_your_Layout_file);
    
         picker.setMinValue(0);
        picker.setMaxValue(3);
        picker.setDisplayedValues(new String[]{"English", "French","Kiswahili","عربى"});
    }
    }
    

提交回复
热议问题