It might be simply that you need to put the beginShape()
before the for loop.
In any case, we are providing an example which seems to do something really close to what you are trying to achieve:
Take a look at ColoredLinesMarker.java for line markers with colors based on the speed. Note, how in that example we are reading the speed from the properties (you don't have to do it like this, but it is good practice). You can find the full example (including the App and a custom reader for GPX files with speed data) here.