Android Horizontal Scroll View for showing youtube vidoes -


am creating android application displays youtube videos on horizontal(landscape) list view similar application in screen-shot. , when click on 1 of video should play, happening, able load youtube videos along there thumbnails in simple list view(vertical) in android, couldn't found out way far, using can show videos in youtube playlist in manner shown in following screen shot layout view.
if 1 knows how show video list in horizontal(landscape) layout depicted in attached screen-shot, great me.

please visit link see screenshot: https://sc-cdn.scaleengine.net/i/954e89ab4d5fef83bb19009107d71c60.png

thank you.

here sample code

sorry logs, running on device.

mainactivity

    package in.wptrafficanalyzer.viewpagerdemo;  import android.os.bundle; import android.support.v4.app.fragmentactivity; import android.support.v4.app.fragmentmanager; import android.support.v4.view.viewpager; import android.view.menu;  public class mainactivity extends fragmentactivity {      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          /** getting reference viewpager defined layout file */                 viewpager pager = (viewpager) findviewbyid(r.id.pager);          /** getting fragment manager */         fragmentmanager fm = getsupportfragmentmanager();          /** instantiating fragmentpageradapter */         myfragmentpageradapter pageradapter = new myfragmentpageradapter(fm);          /** setting pageradapter pager object */         pager.setadapter(pageradapter);      }      @override     public boolean oncreateoptionsmenu(menu menu) {         getmenuinflater().inflate(r.menu.activity_main, menu);         return true;     } } 

myfragment.java

package in.wptrafficanalyzer.viewpagerdemo;  import com.google.android.youtube.player.youtubeinitializationresult; import com.google.android.youtube.player.youtubeplayer; import com.google.android.youtube.player.youtubeplayer.errorreason; import com.google.android.youtube.player.youtubeplayer.playbackeventlistener; import com.google.android.youtube.player.youtubeplayer.playerstatechangelistener; import com.google.android.youtube.player.youtubeplayer.provider; import com.google.android.youtube.player.youtubeplayerview;  import android.os.bundle; import android.support.v4.app.fragment; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup;   public class myfragment extends fragment implements youtubeplayer.oninitializedlistener{      int mcurrentpage;     public static final string api_key = "aizasybaoobw6vr4ucjncxxxxxxxx";      //http://youtu.be/<video_id>     public static final string video_id = "dklftgvysvu";      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);          /** getting arguments bundle object */         bundle data = getarguments();          /** getting integer data of key current_page bundle */         mcurrentpage = data.getint("current_page", 0);      }      @override     public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {         view v = inflater.inflate(r.layout.myfragment_layout, container,false);                      youtubeplayerview tv = (youtubeplayerview ) v.findviewbyid(r.id.youtube_player);         tv.initialize(api_key, this);         return v;            }      @override     public void oninitializationfailure(provider provider, youtubeinitializationresult result) {         //toast.maketext(this, "failured initialize!", toast.length_long).show();     }      @override     public void oninitializationsuccess(provider provider, youtubeplayer player, boolean wasrestored) {         /** add listeners youtubeplayer instance **/         player.setplayerstatechangelistener(playerstatechangelistener);         player.setplaybackeventlistener(playbackeventlistener);          /** start buffering **/         if (!wasrestored) {             player.cuevideo(video_id);         }     }      private playbackeventlistener playbackeventlistener = new playbackeventlistener() {          @override         public void onbuffering(boolean arg0) {         }          @override         public void onpaused() {         }          @override         public void onplaying() {         }          @override         public void onseekto(int arg0) {         }          @override         public void onstopped() {         }      };      private playerstatechangelistener playerstatechangelistener = new playerstatechangelistener() {          @override         public void onadstarted() {         }          @override         public void onerror(errorreason arg0) {         }          @override         public void onloaded(string arg0) {         }          @override         public void onloading() {         }          @override         public void onvideoended() {         }          @override         public void onvideostarted() {         }     }; } 

myfragmentpageradapter.java

package in.wptrafficanalyzer.viewpagerdemo;  import android.os.bundle; import android.support.v4.app.fragment; import android.support.v4.app.fragmentmanager; import android.support.v4.app.fragmentpageradapter;  public class myfragmentpageradapter extends fragmentpageradapter{      final int page_count = 5;      /** constructor of class */     public myfragmentpageradapter(fragmentmanager fm) {         super(fm);     }      /** method invoked when page requested create */     @override     public fragment getitem(int arg0) {          myfragment myfragment = new myfragment();         bundle data = new bundle();         data.putint("current_page", arg0+1);         myfragment.setarguments(data);         return myfragment;     }      /** returns number of pages */     @override     public int getcount() {              return page_count;     }      @override     public charsequence getpagetitle(int position) {                 return "page #" + ( position + 1 );     }     } 

activity_main.xml

<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.support.v4.view.viewpager         android:id="@+id/pager"         android:layout_width="fill_parent"         android:layout_height="fill_parent"     >         <android.support.v4.view.pagertabstrip             android:id="@+id/pager_tab_strip"             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:layout_gravity="top"             android:background="#33b5e5"             android:textcolor="#fff"             android:paddingtop="4dp"             android:paddingbottom="4dp" />      </android.support.v4.view.viewpager>  </relativelayout> 

myfragment_layout.xml

<?xml version="1.0" encoding="utf-8"?>  <linearlayout 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:orientation="vertical" >      <com.google.android.youtube.player.youtubeplayerview         android:id="@+id/youtube_player"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:background="#fff"         android:padding="5dp"          />  </linearlayout> 

androidmanifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="in.wptrafficanalyzer.viewpagerdemo"     android:versioncode="1"     android:versionname="1.0" >      <uses-sdk         android:minsdkversion="4"         android:targetsdkversion="17" />      <application         android:icon="@drawable/ic_launcher"         android:label="@string/app_name"         android:theme="@style/apptheme" >         <activity             android:name=".mainactivity"             android:label="@string/title_activity_main" >             <intent-filter                 android:label="@string/app_name"                 >                 <action android:name="android.intent.action.main" />                  <category android:name="android.intent.category.launcher" />             </intent-filter>         </activity>     </application>     <uses-permission android:name="android.permission.internet" />     <uses-permission android:name="android.permission.write_external_storage" />  </manifest> 

you doing wrong. fragment xml should this:

<?xml version="1.0" encoding="utf-8"?>  <linearlayout 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:orientation="vertical" >   <android.support.v4.view.viewpager         android:id="@+id/pager"         android:layout_width="fill_parent"         android:layout_height="fill_parent"     >     <com.google.android.youtube.player.youtubeplayerview         android:id="@+id/youtube_player"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:background="#fff"         android:padding="5dp"          />  </android.support.v4.view.viewpager> </linearlayout> 

now code accordingly , post logcat crash issue resolution.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -