java - I want to show 3 different fragments for 3 different tabs in view-pager ,Tabbed activity Android -


i new android , time created view-pager tabbed activity looking video tutorial. problem or need show 3 different fragments if user slides position tab1(shows first fragment),tab2 (shows second fragment) tab3 (shows third fragment) showing 1 , fragment tabs

this adapter class named datafragment package com.example.jaison.news;

public class datafragment extends fragment { view view; viewpager viewpager; tablayout tablayout;   @nullable @override public view oncreateview(layoutinflater inflater, @nullable viewgroup container, @nullable bundle savedinstancestate) {     view= inflater.inflate(r.layout.sample,container,false);       viewpager = (viewpager) view.findviewbyid(r.id.viewpager);     viewpager.setadapter(new slideradapter(getchildfragmentmanager()));     tablayout = (tablayout) view.findviewbyid(r.id.sliding_tabs);     tablayout.post(new runnable() {         @override         public void run() {             tablayout.setupwithviewpager(viewpager);         }     });      return view;  }     private class slideradapter extends fragmentpageradapter{      final  string tabs[]={"tab1", "tab2","tab3"};     public slideradapter(fragmentmanager fm) {         super(fm);     }       @override     public fragment getitem(int position) {         fragment fragment = null;          return fragment;     }       @override     public int getcount() {          return 3;     }    @override    public charsequence getpagetitle(int position) {         return tabs[position];    } }      } 

for did not point , need implement code this, not sure this..

        switch (position) {             case 0:                  //showing first fragment               case 1:                       //showing second fragment               case 2:                 //showing third fragment             default:                 return new fragment();         } 

change getitem method

 @override public fragment getitem(int position) {     fragment fragment = null;     switch (position){         case 0:             fragment = new tab1fragment();             break;         case 1:             fragment = new tab2fragment();             break;        case 2:             fragment = new tab3fragment();             break;     }     return fragment; } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -