Ihre Anwendung zum Absturz Wenn Sie versuchen Ansicht aufzublasen mit gleichem Fragment
jedes ListView
Elemente (Wie Vervielfältigung in Fragment-ID wie diese quiz)
Es Zwei-Lösung (einer von ihnen aus @ivagarz Antwort):
1- Sie können nur ein youtube Video YouTubePlayerView
über die ListView
in Ihr Activity
Layout Aber Ihr Activity
Must erstreckt YouTubeBaseActivity
Wie YouTube Android Player API Doc (I Verwendung anzuzeigen Denkens Diese Lösung wird Sie Ihr Problem)
2- lösen dir nicht helfen, YouTubeThumbnailView
können youtube Minibild von Video für jeden Artikel in ListView
mit YouTube-Player-Taste über youtube Minibild verwendet, um die Anzeige von Videos angezeigt werden soll.
Wie Das nächste Bild:
Wenn Benutzer auf youtube Player-Taste, haben Sie zwei Möglichkeiten:
Erste Option YouTubePlayerSupportFragment
: Sie können YouTubeThumbnailView
ersetzen mit YouTubePlayerSupportFragment
Wenn Sie diese Option nehmen, müssen Sie:
A- hinzufügen YouTubePlayerSupportFragment
programmatisch auf dem Fly (zur Vermeidung von Doppelarbeit in Fragment
Id).
B- Nur ein Video in Ihr ListView
anzeigen Als answer of this Question.
Ex:
list_item.xml
Layout für ListView
Artikel:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/parent_relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.google.android.youtube.player.YouTubeThumbnailView
android:id="@+id/youtube_thumbnail"
android:layout_width="fill_parent"
android:layout_height="250dp"
android:scaleType="centerCrop"
android:visibility="gone"/>
<RelativeLayout android:id="@+id/relativeLayout_over_youtube_thumbnail"
android:layout_width="fill_parent"
android:layout_height="250dp"
android:background="@color/color_background_transparent"
android:visibility="gone">
<ImageView android:id="@+id/btnYoutube_player"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="center"
android:src="@drawable/youtube_player"/>
</RelativeLayout>
</RelativeLayout>
in getView
Mehtod von ListView
Adapter:
public View getView(int position, View convertView, ViewGroup parent) {
convertView = inflator.inflate(R.layout.list_item.xml, parent, false);
final RelativeLayout relativeLayoutOverYouTubeThumbnailView = (RelativeLayout) convertView.findViewById(R.id.relativeLayout_over_youtube_thumbnail);
final YouTubeThumbnailView youTubeThumbnailView = (YouTubeThumbnailView) convertView.findViewById(R.id.youtube_thumbnail);
// get parent relative layout
RelativeLayout parentRelativeLayout = (RelativeLayout) convertView.findViewById(R.id.parent_relativeLayout);
// then create dynamic FrameLayout
FrameLayout.LayoutParams dynamicFrameLayoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
final FrameLayout dynamicFrameLayout = new FrameLayout(ctx);
dynamicFrameLayout.setId(Different_ID);
dynamicFrameLayout.setLayoutParams(dynamicFrameLayoutParams);
// then add dynamic FrameLayout as children in parent relative layout
parentRelativeLayout.addView(dynamicFrameLayout);
ImageView youtubePlayerButton = (ImageView) convertView.findViewById(R.id.btnYoutube_player);
youtubePlayerButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
View parentView = (View) v.getParent().getParent();
YouTubeThumbnailView youTubeThumbnailView = (YouTubeThumbnailView) parentView.findViewById(R.id.youtube_thumbnail);
RelativeLayout relativeLayoutOverYouTubeThumbnailView = (RelativeLayout) parentView.findViewById(R.id.relativeLayout_over_youtube_thumbnail);
youTubeThumbnailView.setVisibility(View.GONE);
relativeLayoutOverYouTubeThumbnailView.setVisibility(View.GONE);
YouTubeFragment youTubeFragment = new YouTubeFragment();
youTubeFragment.youTubeFragmentInitialize(VideoID, youTubeFragment, parentView);
getSupportFragmentManager()
.beginTransaction()
.replace(dynamicFrameLayout.getId(), youTubeFragment)
.commit();
}
});
final YouTubeThumbnailLoader.OnThumbnailLoadedListener onThumbnailLoadedListener = new YouTubeThumbnailLoader.OnThumbnailLoadedListener(){
@Override
public void onThumbnailError(YouTubeThumbnailView youTubeThumbnailView, YouTubeThumbnailLoader.ErrorReason errorReason) {
}
@Override
public void onThumbnailLoaded(YouTubeThumbnailView youTubeThumbnailView, String s) {
loadingImage.setVisibility(View.GONE);
youTubeThumbnailView.setVisibility(View.VISIBLE);
relativeLayoutOverYouTubeThumbnailView.setVisibility(View.VISIBLE);
}
};
youTubeThumbnailView.initialize(API_KEY, new YouTubeThumbnailView.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubeThumbnailView youTubeThumbnailView, YouTubeThumbnailLoader youTubeThumbnailLoader) {
youTubeThumbnailLoader.setVideo(VideoID);
youTubeThumbnailLoader.setOnThumbnailLoadedListener(onThumbnailLoadedListener);
}
@Override
public void onInitializationFailure(YouTubeThumbnailView youTubeThumbnailView, YouTubeInitializationResult youTubeInitializationResult) {
}
});
}
ich meine eigenen erstellt wurde Fragment
von YouTubePlayerSupportFragment
erweitert:
public class YouTubeFragment extends YouTubePlayerSupportFragment {
public void youTubeFragmentInitialize(final String videoId, final YouTubeFragment fragment, final View parent) {
fragment.initialize(apiKey, new YouTubePlayer.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, final YouTubePlayer youTubePlayer, boolean wasRestored) {
youTubePlayer.setShowFullscreenButton(false);
if (!wasRestored) {
youTubePlayer.loadVideo(videoId);
}
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
Log.e("app", youTubeInitializationResult.toString());
}
});
}
}
Zweite Option YouTubeStandalonePlayer
oder Erstellen Ihrer eigenen Activity
erstreckt YouTubeBaseActivity
: Nur wenn Benutzer auf YouTube-Player-Taste können Sie eine Intent erstellen neue Aktivität zu öffnen Video anzuzeigen Sie
Intent intent = YouTubeStandalonePlayer.createVideoIntent(context, YOUR_DEVELOPER_KEY, VIDEO_ID);
startActivity(intent);
Kann teilen Sie die Ausgabe dieses Befehls 'adb shell dumpsys Aktivität'? Es enthält die Liste der aktiven und hinzugefügten Fragmente. –
Verwenden Sie Fragmente der Support-Bibliothek? – Yuraj
Ja. Ich habe Support-Bibliothek Fragmente. –