android - how to return fragment of compatible type -
i using viewpager fragments. defined 3 fragments, each in separate class file "frag_1, frag_2, frag_3" extends fragment class. when instantiate , object of fragment class shown below in switch-case receive incompatible type error , says:
required xx.xx.xx.app.fragment , found vpager_00.frag_1
how solve it
code:
public class vpageradapter extends fragmentstatepageradapter { private int mnumoftabs; public vpageradapter(fragmentmanager fm, int numoftabs) { super(fm); this.mnumoftabs = numoftabs; } @override public fragment getitem(int position) { switch (position) { case 0: frag_1 tab1 = new frag_1(); return tab1; case 1: frag_2 tab2 = new frag_2(); return tab2; case 2: frag_3 tab3 = new frag_3(); return tab3; default: return null; } }
imports in vpageradapter class:
import android.support.v4.app.fragment; import android.support.v4.app.fragmentmanager; import android.support.v4.app.fragmentstatepageradapter; import com.example.com.vpager_00.frag_1; import com.example.com.vpager_00.frag_2; import com.example.com.vpager_00.frag_3;
Comments
Post a Comment