I think they were always attracted to each other, it's just that sometimes you have to wait before people realize their mistakes and start to mature.
In James' case it was just a matter of time, because he wanted to attract Lily's attention and I think he realized that his childish attitude won't help. People like to fool around for no reason, but sometimes it just doesn't help reach the goal
