title: Display a list of Youtube Videos in Android inside a ListView
body: <p>i want display a list oy youtube videos inside a listView.
  i am using a fragment not an activity.
  here is the fragment :</p>
  
  <pre><code>public class VideosFragment extends Fragment{
  ...
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, 
  Bundle savedInstanceState) {
      // Inflate the layout for this fragment
      return inflater.inflate(R.layout.fragment_videos, container, false);
  }
  
  @Override
  public void onViewCreated(View view, @Nullable Bundle savedInstanceState){
      //assign video
      mVideosListView = getView().findViewById(R.id.videoLV);
  
      fetchVideos();
  
      /***populate video list to adapter**/
      mVideoAdapter = new VideoAdapter(getContext(), mVideosList, this);
      mVideosListView.setAdapter(mVideoAdapter);
  }
  }
  </code></pre>
  
  <p><strong>fragment_videos layout</strong> :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  
  &lt;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:background="@color/colorBackground"
  android:orientation="vertical"
  tools:context=".VideosFragment"&gt;
  
  &lt;ListView
      android:id="@+id/videoLV"
      android:layout_width="match_parent"
      android:layout_height="match_parent"/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>in my adapter i am trying to insert multiple YouTubePlayerSupportFragment dynamically .</p>
  
  <p><strong>VideoAdapter</strong> :</p>
  
  <pre><code>public class VideoAdapter extends ArrayAdapter&lt;Video&gt; {
  
  private Context mContext;
  private Fragment frgmt;
  private List&lt;Video&gt; mVideos;
  
  public VideoAdapter(@NonNull Context context, @NonNull List&lt;Video&gt; objects, Fragment frg) {
      super(context, R.layout.single_row_video, objects);
      mContext = context;
      mVideos = objects;
      frgmt = frg;
  }
  @Override
  public View getView(final int position, View convertView, ViewGroup parent) {
      final ViewHolder holder;
      YouTubePlayerSupportFragment videoFragment = new YouTubePlayerSupportFragment();
      if (convertView == null) {
          convertView = LayoutInflater.from(mContext).inflate(R.layout.single_row_video, null);
          holder = new ViewHolder();
          holder.videoView = convertView.findViewById(R.id.videoView);
          FragmentTransaction transaction = frgmt.getChildFragmentManager().beginTransaction();
          transaction.add(R.id.videoView, videoFragment).commit();
  
          convertView.setTag(holder);
      } else {
          holder = (ViewHolder) convertView.getTag();
      }try {
          Video video = mVideos.get(position);
          final String url = video.getVideoUrl(); // your URL here
  
          videoFragment.initialize("AIza.....13Ao", new YouTubePlayer.OnInitializedListener() {
                  @Override
                  public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
                      if (!b) {
                          youTubePlayer.cueVideo(url);
                      }
                  }
  
                  @Override
                  public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult result) {
                      if (result.isUserRecoverableError()) {
                          result.getErrorDialog(frgmt.getActivity(), 1).show();
                      } else {
                          Toast.makeText(frgmt.getActivity(), "YouTubePlayer.onInitializationFailure(): " + result.toString(), Toast.LENGTH_LONG).show();
                      }
                  }
              });
      } catch (Exception e) {
          Log.e("Youtube Video error", e.getMessage());
      }
      return convertView;
  }
  
  public static class ViewHolder {
      FrameLayout videoView;
  }
  }
  </code></pre>
  
  <p>and this is <strong>single_row_video</strong> layout :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:padding="10dp"
  android:orientation="vertical"&gt;
  
  &lt;android.support.v7.widget.CardView
      android:layout_width="match_parent"
      android:layout_height="wrap_content"&gt;
  
      &lt;FrameLayout
          android:layout_gravity="center"
          android:layout_margin="2dp"
          android:id="@+id/videoView"
          android:layout_width="match_parent"
          android:layout_height="200dp" /&gt;
  
  &lt;/android.support.v7.widget.CardView&gt;
  </code></pre>
  
  <p></p>
  
  <p>the problem is i am getting a single video displayed from the list , the other fragments looks empty , i dont know if it's a clean way to achieve my goal.
  is there any better idea or a change to do it ? thank you.</p>