I'm taking an Android class based on this book: http://www.deitel.com/Books/Android/AndroidforProgrammers/tabid/3606/Default.aspx
I'm working on the TipCalculator example, though it's been modified by the professor I think (to make it work with the new versions and he got the project most of the way done. It's TipCalculator-partial-layout.zip). I don't understand the concepts of how the stuff in the java file knows what seekbar to listen to. Can someone explain it to me? I've been told it has to do with the id, but I don't understand what that means.
This is a snippet from the main.xml file regarding the seekbar:
<SeekBar
android:id="@+id/customSeekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_span="2"
>
</SeekBar>
This is a snippet from the main.xml file regarding the seekbar:
(part of onCreate)
// get the SeekBar used to set the custom tip amount
SeekBar customSeekBar = (SeekBar) findViewById(R.id.customSeekBar);
customSeekBar.setOnSeekBarChangeListener(customSeekBarListener);
Then there's the listener object:
private OnSeekBarChangeListener customSeekBarListener =
new OnSeekBarChangeListener()
{
// update currentCustomPercent, then call updateCustom
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser)
{
// sets currentCustomPercent to position of the SeekBar's thumb
currentCustomPercent = seekBar.getProgress();
updateCustom(); // update EditTexts for custom tip and total
} // end method onProgressChanged
@Override
public void onStartTrackingTouch(SeekBar seekBar)
{
} // end method onStartTrackingTouch
@Override
public void onStopTrackingTouch(SeekBar seekBar)
{
} // end method onStopTrackingTouch
}; // end OnSeekBarChangeListener