android - SlidingTabLayout not displaying on output -
i using android studio 1.2.2 , trying implement tabs 1 of activities. have added code don't seem getting output on phone. not need actionbar, slidingtablayout, doesn't show other blank screen when run.
iphone6activity.java
package com.hashmi.omar.vodafonestore; import android.app.activity; import android.graphics.typeface; import android.os.bundle; import android.support.annotation.nullable; import android.support.v4.app.fragment; import android.support.v4.app.fragmentmanager; import android.support.v4.app.fragmentpageradapter; import android.support.v4.view.viewpager; import android.support.v7.app.actionbaractivity; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.textview; public class iphone6activity extends activity { private viewpager mpager; private slidingtablayout mtabs; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_iphone6); //sets font text //typeface vodalt = typeface.createfromasset(getassets(), "vodafonelt.ttf"); //textview vodaheading = (textview) findviewbyid(r.id.textview10); // vodaheading.settypeface(vodalt); mpager = (viewpager) findviewbyid(r.id.ip6pager); //mpager.setadapter(new mypageradapter(getsupportfragmentmanager())); mtabs = (slidingtablayout) findviewbyid(r.id.ip6tabs); mtabs.setviewpager(mpager); } class mypageradapter extends fragmentpageradapter{ string[] tabs; public mypageradapter(fragmentmanager fm) { super(fm); tabs=getresources().getstringarray(r.array.tabs); } @override public fragment getitem(int position) { myfragment myfragment=myfragment.getinstance(position); return myfragment; } @override public charsequence getpagetitle(int position){ return tabs[position]; } @override public int getcount() { return 3; } } public static class myfragment extends fragment{ private textview textview; public static myfragment getinstance(int position){ myfragment myfragment = new myfragment(); bundle args = new bundle(); args.putint("position", position); myfragment.setarguments(args); return myfragment; } @override public view oncreateview(layoutinflater inflater, @nullable viewgroup container, @nullable bundle savedinstancestate) { view layout=inflater.inflate(r.layout.fragment_my, container, false); textview= (textview) layout.findviewbyid(r.id.position); bundle bundle=getarguments(); if(bundle!=null) { textview.settext("the page selected "+bundle.getint("position")); } return layout; } } }
activity_iphone6.xml
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/iphone6" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.hashmi.omar.vodafonestore.iphone6activity" android:background="#ffffffff"> <com.hashmi.omar.vodafonestore.slidingtablayout android:id="@+id/ip6tabs" android:layout_width="match_parent" android:layout_height="wrap_content" /> <android.support.v4.view.viewpager android:id="@+id/ip6pager" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" /> </linearlayout>
fragment_my.xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> </linearlayout>
you not using mypageradapter class. uncomment out line set adapter viewpager:
//mpager.setadapter(new mypageradapter(getsupportfragmentmanager()));
Comments
Post a Comment