Effective resource allocation plays a pivotal role in wireless networks. Unfortunately, typical resource allocation problems are mixed-integer nonlinear programming (MINLP) problems, which are NP-hard. Machine learning based methods recently emerge as a disruptive way to obtain near-optimal performance for MINLP problems with affordable computational complexity. However, they suffer from severe performance deterioration when the network parameters change, which commonly happens in practice and can be characterized as the task mismatch issue. In this paper, we propose a transfer learning method via self-imitation, to address this issue for effective resource allocation in wireless networks. It is based on a general "learning to optimize" framework for solving MINLP problems. A unique advantage of the proposed method is that it can tackle the task mismatch issue with a few additional unlabeled training samples, which is especially important when transferring to large-size problems. Numerical experiments demonstrate that the proposed method, with much less training time, achieves comparable performance with the model trained from scratch based on sufficient labeled samples. To the best of our knowledge, this is the first work that applies transfer learning for resource allocation in wireless networks.