You're going to do this just like a click listener on a button.
np1.setOnValueChangedListener(new OnValueChangeListener() {
@Override
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
// do something here
}
});
A fully working example can be found here: http://samplecodez.com/android/numberpicker.php
Some stylistic points ...
- Main should be capitalized and it's a good practice to make it more descriptive like MainActivity.
- Use fields only when necessary. I'm guessing you're not using most of those variables outside of onCreate() so make them local variables instead.
- TextView totalCost is your best named variable of the lot :) Consider using verbose names. You'll thank yourself 6 months down the road when you look back at this code for the first time in a long time.
- No magic values (or Strings)! Create a constant for your min and max values and those should be private static final int with the your fields.
- In Eclipse setup the java save actions in preferences to auto format all lines of code when you save.
Of course none of those things will make your code run any better, but it sure will be easier to read.