问题
Does anyone know where can I find a tutorial or example on how to achive this kind of number picker dialog on android? I googled everything but only managed to find examples where you have to create your own buttons with custom images etc. Can this be done in simple way?
All I could find was this: http://www.quietlycoding.com/?p=5 but it doesn't quite help me.
回答1:
If you are targeting API level 11 or higher, you can use NumberPicker
If you are targeting earlier API levels, you will have to write your own NumberPicker or use one from a third party library.
Here is a nice video tutorial.
Good luck!
回答2:
The easiest way you can go with this is to use default Android NumberPicker.
The way to design it like you want is to create your custom dialog and embed one of those in it such as:
LayoutInflater inflater = (LayoutInflater)
getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View npView = inflater.inflate(R.layout.number_picker_dialog_layout, null);
return new AlertDialog.Builder(this)
.setTitle("Text Size:")
.setView(npView)
.setPositiveButton(R.string.dialog_ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
})
.setNegativeButton(R.string.dialog_cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
})
.create();
来源:https://stackoverflow.com/questions/11800589/number-picker-dialog