android - Why my "viewpager" is not working? -


when run app, getting blank screen. have 2 fragments , xml files.

following entire code:

activity_main.xml

<?xml version="1.0" encoding="utf-8"?> <relativelayout     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:paddingleft="@dimen/activity_horizontal_margin"     android:paddingright="@dimen/activity_horizontal_margin"     android:paddingtop="@dimen/activity_vertical_margin"     android:paddingbottom="@dimen/activity_vertical_margin"     tools:context="autogenie.designtrial.mainactivity">      <android.support.v4.view.viewpager         android:layout_width="match_parent"         android:layout_height="300dp"         android:id="@+id/view"         android:layout_alignparentbottom="true"         android:layout_alignparentend="true"         android:layout_below="@+id/list" />  </relativelayout> 

mainactivity.java

package autogenie.designtrial;  import android.support.annotation.nonnull; import android.support.v4.app.fragment; import android.support.v4.app.fragmentactivity; import android.support.v4.app.fragmentstatepageradapter; import android.support.v4.view.viewpager; import android.support.v7.app.appcompatactivity; import android.os.bundle;  import java.util.arraylist; import java.util.collection; import java.util.iterator; import java.util.list; import java.util.listiterator;  public class mainactivity extends fragmentactivity {      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);         viewpager v=(viewpager)findviewbyid(r.id.view);         list<fragment> fragments=new arraylist<>();         fragments.add(fragment.instantiate(this, frag1.class.getname()));         fragments.add(fragment.instantiate(this, frag2.class.getname()));          fragpageadapter fragpageadapter0=new fragpageadapter(getsupportfragmentmanager(),fragments);         v.setadapter(fragpageadapter0);     }  } 

frag1.java

package autogenie.designtrial;  import android.os.bundle; import android.support.v4.app.fragment; import android.support.v4.app.fragmentactivity; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup;  /**  * created sadhana on 25/1/16.  */ public class frag1 extends fragment {      @override     public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) {         // inflate , locate main imageview         final view v1 = inflater.inflate(r.layout.frag1, container, false);         //...         return v1;     }  } 

frag1.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"     android:gravity="center">      <radiobutton         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:text="new radiobutton"         android:id="@+id/radiobutton2"         android:layout_gravity="center" /> </linearlayout> 

frag2.java

package autogenie.designtrial;  import android.os.bundle; import android.support.v4.app.fragment; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup;  /**  * created sadhana on 25/1/16.  */ public class frag2 extends fragment {      public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) {         // inflate , locate main imageview         final view v3 = inflater.inflate(r.layout.frag2, container, false);         //...         return v3;     } } 

frag2.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"     android:gravity="center">      <seekbar         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:id="@+id/seekbar" /> </linearlayout> 

fragpageadapter.java

package autogenie.designtrial;  import android.support.v4.app.fragment; import android.support.v4.app.fragmentmanager; import android.support.v4.app.fragmentpageradapter;  import java.util.arraylist; import java.util.list;  public class fragpageadapter extends fragmentpageradapter {      list<fragment> f;      public fragpageadapter(fragmentmanager fm,list<fragment> f) {         super(fm);         this.f=f;     }      @override     public fragment getitem(int position) {         fragment fragment =null;         switch (position) {             case 0:                 fragment = f.get(position);                 break;             case 1:                 fragment = f.get(position);                 break;}         return fragment;     }      @override     public int getcount() {         return 0;     } } 

you returning 0 in getcount() of fragpageadapter

@override public int getcount() {     return 0; } 

change f.size() list.size

@override public int getcount() {     return f.size; } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -