Skip to content

Instantly share code, notes, and snippets.

@tonY1883
Last active May 14, 2018 07:22
Show Gist options
  • Save tonY1883/a650a0978979224345637540d979b769 to your computer and use it in GitHub Desktop.
Save tonY1883/a650a0978979224345637540d979b769 to your computer and use it in GitHub Desktop.
Android number picker dialog
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="16dp"
android:orientation="vertical">
<NumberPicker
android:id="@+id/picker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
private void showPickerDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
final View view = this.getLayoutInflater().inflate(R.layout.dialog_picker, null);
builder.setView(view);
//builder.setTitle();
final NumberPicker picker = (NumberPicker) view.findViewById(R.id.picker);
//picker.setMinValue();
//picker.setMaxValue();
//picker.setValue();
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
//positive button action
}
})
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
//negative button action
}
});
builder.create().show();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment