I assume you are talking about Huck's attitude in Chapter 4 of the book. First, please note that it is not really a "sudden" change but more of a gradual one. Huck comes to like school better because he is getting to be more used to "civilized" ways. As he says,
I liked the old ways best, but I was getting so I liked the new ones, too, a little bit.
This shows in the fact that Huck hasn't completely taken to school. He still needs to play hooky every now and then and get beaten for it so that he can still feel that he hasn't completely changed.
Twain has Huck start to like school and civilized ways so that his father's reappearance will be more jarring. When Pap comes back, it really shocks Huck and pulls him back towards a life that he had been moving away from.