First of all i have an application with an expandablelistview, so far everything woks, but what i want to do is when every child in each parent is clicked a new YouTube video is opened, i know how to do this but the problem is that there are A LOT of items in each list and each item/child plays its own video.
Is there a way for me to just do an IF statement inside the onInitializationSuccess method where it takes a item from the array created depending on which child was clicked on the Expandable list class i have.
public class Videos extends YouTubeBaseActivity implements
YouTubePlayer.OnInitializedListener {
static private final String DEVELOPER_KEY = "wqafesf968se15fes6fe...";
static private final String VIDEO = "MveeQaTefwaewRE";
public final String VideoList[]={"MvJT5E","LKKdpJU"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.videos);
YouTubePlayerView youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
youTubeView.initialize(DEVELOPER_KEY, this);
}
@Override
public void onInitializationFailure(Provider provider,
YouTubeInitializationResult error) {
Toast.makeText(this, "Oh no! " + error.toString(), Toast.LENGTH_LONG)
.show();
}
@Override
public void onInitializationSuccess(Provider provider,
YouTubePlayer player, boolean wasRestored) {
player.loadVideo(VIDEO);
// IF statement here with an item from the array depending on which child was clicked
player.addFullscreenControlFlag(YouTubePlayer.FULLSCREEN_FLAG_ALWAYS_FULLSCREEN_IN_LANDSCAPE);
}
}
Here is the onClick method which is in ANOTHER class which that extends Activity
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
final String selected = (String) listAdapter.getChild(groupPosition, 1);
switch (groupPosition) {
case 0:
switch (childPosition) {
case 0:
Intent adobeEFintro = new Intent("com.program.STUFF");
startActivity(adobeEFintro);
break;
case 1:
break;
case 2:
break;
case 3:
break;
default:
break;
}
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
default:
Toast.makeText(getBaseContext(), selected, Toast.LENGTH_SHORT).show();
break;
}
return false;
}
You could construct an array of URLS in the class containing the onClick method which passes the URL directly to the Video class. This is explained in How do I pass data between Activities in Android application?
Intent intent = new Intent(v.getContext(), Video.class);
intent.putExtra("URL", <insertUrlHere>);
startActivity(intent)
In the Video activity:
Bundle extras = getIntent().getExtras();
if (extras != null) {
String value = extras.getString("URL");
}