1
votes

I have a certain issue that I am trying to work around. Any Advice would be awesome.

I already know how to integrate the youtube player and thumbnails into my main activity in android studio. However I want to do it a different way and have done quite a lot of research on it and have come up short.

My Issue: I want to create a Gridview in my main activity, then create a seperate row layout and adapter to use with the gridview in the main activity so that I can display multiple thumbnails at a time. The thing is that my Adapter class already extends "ArrayAdapter" and in order for my adapter to set a different "VIDEO_ID" for each thumbnail, I need it to extend "YouTubeBaseActivity" so that I can use:

@Override
public void onInitializationSuccess(YouTubeThumbnailView thumbnailView,
                                    YouTubeThumbnailLoader thumbnailLoader)"

the method within my adapter. However, I know in JAVA that you can only inherit from one class.

So can anyone give me some advice on a possible workaround?

Code that I require assistance on:

  • The MainActivity:

    public class FanHome extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener, YouTubeThumbnailView.OnInitializedListener { private YouTubePlayer youTubePlayer; private YouTubePlayerView youTubePlayerView; private YouTubeThumbnailView youTubeThumbnailView; private YouTubeThumbnailLoader youTubeThumbnailLoader;

    private String[] tempVideos = {"Video1","Video2","Video3","Video4","Video5","Video6","Video7"
                                    ,"Video8","Video9","Video10"};
    
    @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_fan_home);
     ListAdapter theAdapter = new VideoGridAdapter(this,tempVideos);
        GridView theGridView = (GridView)findViewById(R.id.gridViewYoutubeThumbnails);
        theGridView.setAdapter(theAdapter);
    
     youTubeThumbnailView = (YouTubeThumbnailView)findViewById(R.id.youtubethumb);
        youTubeThumbnailView.initialize(DeveloperKey.DEVELOPER_KEY, this);
        youTubeThumbnailView.setOnClickListener(new View.OnClickListener(){
    
     @Override
        public void onClick(View arg0) {
    
      }});
    }
    
  • The VideoGridAdapter:

    public class VideoGridAdapter  extends ArrayAdapter<String> {
    public VideoGridAdapter(Context context, String[] values) {
        super(context, R.layout.row_grid_videos, values);
    }
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater theInflater = LayoutInflater.from(getContext());
        final View theView = theInflater.inflate(R.layout.row_grid_videos, parent, false);
        String videoSelected = getItem(position);
    
        if (videoSelected.equals("Video1")) {
            String VIDEO_ID = "o7VVHhK9zf0";
        }
    
        return theView;
    }
    
  • The row_grid_videos layout:

    <com.google.android.youtube.player.YouTubeThumbnailView
        android:id="@+id/youtubethumb"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="5dp" />
    
    <LinearLayout
        android:id="@+id/panelPraisePurge"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="bottom"
        android:orientation="horizontal"
        android:paddingLeft="5dp"
        android:paddingRight="5dp">
    
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="horizontal">
    
            <ImageView
                android:id="@+id/imageViewDislike"
                android:layout_width="20dp"
                android:layout_height="20dp"
                app:srcCompat="@drawable/ic_purge" />
    
            <TextView
                android:id="@+id/textViewDislike"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="25" />
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="right"
            android:orientation="horizontal">
    
            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="20dp"
                android:layout_height="20dp"
                app:srcCompat="@drawable/ic_praise" />
    
            <TextView
                android:id="@+id/textView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="50" />
        </LinearLayout>
    
    </LinearLayout>
    

  • The MainAcitivity layout

    <GridView
        android:id="@+id/gridViewYoutubeThumbnails"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:numColumns="auto_fit">
    </GridView>
    
1
Please post the code instead of explaining the code you triedRino
It's a bit complicated to just post the one sectionShaldon Nienaber

1 Answers

0
votes

Great, I found the solution to my issue. https://androidtutorialmagic.wordpress.com/my-mini-project/multiple-youtube-video-in-recyclerviewlistview-in-android/

This website above explains how to use an Adapter to Call in Thumbnails from "known" youtube videos. However it sets it in a list format instead of a grid format. So the only thing that needs to be changed in the above website is:

LinearLayoutManager linearLayoutManager=new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(linearLayoutManager);

To:

 GridLayoutManager gridLayoutManager = new GridLayoutManager(this,2);
    recyclerView.setLayoutManager(gridLayoutManager);