android - How to use fragment with Viewpager for Swipe pages -


i got doubt regarding viewpager , fragment .i want create swipe view need fragment classes viewpager .how implement such thing!!

i searched through net got using viewpager!!

   public class viewpagerfragmentactivity extends fragmentactivity {      private pageradapter mpageradapter;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         super.setcontentview(r.layout.viewpager_layout);          // initialsie pager         this.initialisepaging();     }      /**      * initialize fragments paged      */     private void initialisepaging() {          list<fragment> fragments = new vector<fragment>();         fragments.add(fragment.instantiate(this, fragment0.class.getname()));         fragments.add(fragment.instantiate(this, fragment1.class.getname()));         fragments.add(fragment.instantiate(this, fragment2.class.getname()));         this.mpageradapter = new mypageradapter(super.getsupportfragmentmanager(), fragments);          viewpager pager = (viewpager) super.findviewbyid(r.id.viewpager);         pager.setadapter(this.mpageradapter);     } } 

manifest file:

 <application android:icon="@drawable/icon" android:label="@string/app_name">         <activity android:name="slider.example.viewpagerfragmentactivity"                   android:label="@string/app_name">             <intent-filter>                 <action android:name="android.intent.action.main" />                 <category android:name="android.intent.category.launcher" />             </intent-filter>         </activity>         <activity android:name="slider.example.fragment0" android:theme="@android:style/theme.notitlebar" android:screenorientation="portrait" />         <activity android:name="slider.example.fragment1" android:theme="@android:style/theme.notitlebar" android:screenorientation="portrait" />         <activity android:name="slider.example.fragment2" android:theme="@android:style/theme.notitlebar" android:screenorientation="portrait" /> <activity android:name=".mypageradapter"></activity>     </application> 

error:

04-05 13:22:39.804: e/androidruntime(468): fatal exception: main 04-05 13:22:39.804: e/androidruntime(468): java.lang.runtimeexception: unable instantiate activity componentinfo{slider.example/slider.example.viewpagerfragmentactivity}: java.lang.classnotfoundexception: slider.example.viewpagerfragmentactivity in loader dalvik.system.pathclassloader[/data/app/slider.example-2.apk] 04-05 13:22:39.804: e/androidruntime(468):  @ android.app.activitythread.performlaunchactivity(activitythread.java:1569) 04-05 13:22:39.804: e/androidruntime(468):  @ android.app.activitythread.handlelaunchactivity(activitythread.java:1663) 04-05 13:22:39.804: e/androidruntime(468):  @ android.app.activitythread.access$1500(activitythread.java:117) 04-05 13:22:39.804: e/androidruntime(468):  @ android.app.activitythread$h.handlemessage(activitythread.java:931) 04-05 13:22:39.804: e/androidruntime(468):  @ android.os.handler.dispatchmessage(handler.java:99) 04-05 13:22:39.804: e/androidruntime(468):  @ android.os.looper.loop(looper.java:123) 04-05 13:22:39.804: e/androidruntime(468):  @ android.app.activitythread.main(activitythread.java:3683) 04-05 13:22:39.804: e/androidruntime(468):  @ java.lang.reflect.method.invokenative(native method) 04-05 13:22:39.804: e/androidruntime(468):  @ java.lang.reflect.method.invoke(method.java:507) 04-05 13:22:39.804: e/androidruntime(468):  @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:839) 04-05 13:22:39.804: e/androidruntime(468):  @ com.android.internal.os.zygoteinit.main(zygoteinit.java:597) 04-05 13:22:39.804: e/androidruntime(468):  @ dalvik.system.nativestart.main(native method) 04-05 13:22:39.804: e/androidruntime(468): caused by: java.lang.classnotfoundexception: slider.example.viewpagerfragmentactivity in loader dalvik.system.pathclassloader[/data/app/slider.example-2.apk] 04-05 13:22:39.804: e/androidruntime(468):  @ dalvik.system.pathclassloader.findclass(pathclassloader.java:240) 04-05 13:22:39.804: e/androidruntime(468):  @ java.lang.classloader.loadclass(classloader.java:551) 04-05 13:22:39.804: e/androidruntime(468):  @ java.lang.classloader.loadclass(classloader.java:511) 04-05 13:22:39.804: e/androidruntime(468):  @ android.app.instrumentation.newactivity(instrumentation.java:1021) 04-05 13:22:39.804: e/androidruntime(468):  @ android.app.activitythread.performlaunchactivity(activitythread.java:1561) 04-05 13:22:39.804: e/androidruntime(468):  ... 11 more 

could guide me @thanks !!

i found tutorial realy clear , helpful creating fragment viewpager:

http://thepseudocoder.wordpress.com/2011/10/13/android-tabs-viewpager-swipe-able-tabs-ftw/

check out, in addiotion please refer here well:

http://androidtrainningcenter.blogspot.co.il/2012/10/viewpager-example-in-android.html http://manishkpr.webheavens.com/android-viewpager-example/ http://manishkpr.webheavens.com/android-viewpager-circle-style-example/

viewpager without tabs:

http://thepseudocoder.wordpress.com/2011/10/05/android-page-swiping-using-viewpager/

update:

first of remove part:

<activity android:name="slider.example.fragment0" android:theme="@android:style/theme.notitlebar" android:screenorientation="portrait" /> <activity android:name="slider.example.fragment1" android:theme="@android:style/theme.notitlebar" android:screenorientation="portrait" /> <activity android:name="slider.example.fragment2" android:theme="@android:style/theme.notitlebar" android:screenorientation="portrait" /> <activity android:name=".mypageradapter"></activity> 

not fragments or adapter not activities , shouldn't write them manifest file.

and try change part:

<activity android:name="slider.example.viewpagerfragmentactivity"               android:label="@string/app_name">         <intent-filter>             <action android:name="android.intent.action.main" />             <category android:name="android.intent.category.launcher" />         </intent-filter>     </activity> 

to this:

<activity android:name=".viewpagerfragmentactivity"               android:label="@string/app_name">         <intent-filter>             <action android:name="android.intent.action.main" />             <category android:name="android.intent.category.launcher" />         </intent-filter>     </activity> 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -