Hallo
Ich will eine app machen in der es links eine Bilder Gallery gibt und rechts Videos.
http://www.learn2crack.com/201…w-tab-layout-example.html
Die Tabs funktionieren plus auf der linken Seite die gallery. Jetzt hab ich das Problem das die Video Klasse für die tabs extens Fragment sein muss und für den youtube player irgendwas mit YoutubeFraggment.
Code
public class Android extends Fragment {
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View android = inflater.inflate(R.layout.android_frag, container, false); ((TextView)android.findViewById(R.id.textView)).setText("Android");
return android;
}
}
Code
public class TabsPagerAdapter extends FragmentStatePagerAdapter {
public TabsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int i) {
switch (i) {
case 0:
//Fragement for Pictures Tab
return new Pictures();
case 1:
//Fragment for Movies Tab
return new Movies();
}
return null;
}
@Override
public int getCount() {
return 2; //No of Tabs
}
}
Alles anzeigen
Java
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.Toast;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerFragment;
import com.google.android.youtube.player.YouTubePlayerSupportFragment;
import com.google.android.youtube.player.YouTubePlayerView;
import com.google.android.youtube.player.internal.y;
import java.util.ArrayList;
import java.util.List;
public class Movies extends YouTubePlayerSupportFragment implements
YouTubePlayer.OnInitializedListener {
public static final String API_KEY = "AIzaSyCe6tORd9Ch4lx-9Ku5SQ476uS9OtZYsWA";
public static final String VIDEO_ID = "o7VVHhK9zf0";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View movies = inflater.inflate(R.layout.movies_frag, container, false);
YouTubePlayerSupportFragment player = (YouTubePlayerSupportFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.youtube_fragment);
return movies;
}
@Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean b) {
if (!b) {
youTubePlayer.cueVideo(VIDEO_ID);
}
}
@Override
public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {
Toast.makeText(getActivity(),
"onInitializationFailure()",
Toast.LENGTH_LONG).show();
}
}
Alles anzeigen
gruß
martinklaus