Maybe this question is asked before but I am not getting how to resolve this issue,so when I use Youtube API in my application under Firebase RecyclerView I got this error that "Variable 'youtuber' is accessed from within inner class, needs to be declared final" and it wont go unless I use final keyword, so due to this I am unable to get data from my database because the value cant be changed to String as it gets fixed by using "Final", can anyone help me with this so that I can use the youtuber String without declaring it final.
I have tried using the Global variable but that also does not work here, Please help.
I am using Android Studio.
Youtube activity code:
public class YoutubeVideos extends AppCompatActivity {
private RecyclerView YouRecycler;
private DatabaseReference YDatabaseReference;
public static String DEVELOPER_KEY = "AIzaSyAEK3iPoxfItaHJsiuJ_693tuuQjkdGfQk";
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.youtube_videos);
YDatabaseReference = FirebaseDatabase.getInstance().getReference().child("you");
YouRecycler = (RecyclerView)findViewById(R.id.Youtube_recycler);
YouRecycler.setHasFixedSize(true);
YouRecycler.setLayoutManager(new LinearLayoutManager(this));
}
@Override
public void onStart() {
super.onStart();
final FirebaseRecyclerAdapter<post2youtube, youtubeViewHolder> youFirebaseAdapter = new FirebaseRecyclerAdapter<post2youtube, youtubeViewHolder>(
post2youtube.class,
R.layout.youtube_card_view,
youtubeViewHolder.class,
YDatabaseReference
) {
@Override
protected void populateViewHolder(youtubeViewHolder yviewHolder, post2youtube ymodel, int position) {
yviewHolder.setYoutube(ymodel.getYoutube());
}
};
YouRecycler.setAdapter(youFirebaseAdapter);
}
public static class youtubeViewHolder extends RecyclerView.ViewHolder {
View youView;
public youtubeViewHolder(View itemView) {
super(itemView);
youView = itemView;
}
public void setYoutube( String youtuber){
YouTubeThumbnailView youPlay = (YouTubeThumbnailView)youView.findViewById(R.id.youtubler);
youPlay.initialize(DEVELOPER_KEY, new YouTubeThumbnailView.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubeThumbnailView youTubeThumbnailView, final YouTubeThumbnailLoader youTubeThumbnailLoader) {
youTubeThumbnailLoader.setVideo(youtuber);
youTubeThumbnailLoader.setOnThumbnailLoadedListener(new YouTubeThumbnailLoader.OnThumbnailLoadedListener() {
@Override
public void onThumbnailLoaded(YouTubeThumbnailView youTubeThumbnailView, String s) {
youTubeThumbnailLoader.release();
}
@Override
public void onThumbnailError(YouTubeThumbnailView youTubeThumbnailView, YouTubeThumbnailLoader.ErrorReason errorReason) {
}
});
}
@Override
public void onInitializationFailure(YouTubeThumbnailView youTubeThumbnailView, YouTubeInitializationResult youTubeInitializationResult) {
}
});
}
}