首先,我有一个带有expandablelistview的应用程序,到目前为止所有内容都已经开始了,但我想要做的是当每个父母的每个孩子都被点击时,一个新的YouTube视频被打开,我知道如何做但这个问题是每个列表中有很多项目,每个项目/孩子都会播放自己的视频。
我有没有办法在onInitializationSuccess方法中执行一个IF语句,它根据在我可扩展列表类中单击的子项,从创建的数组中获取一个项目。
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);
}
}
这是onClick方法,它在ANOTHER类中,它扩展了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;
}
答案 0 :(得分:0)
您可以在包含onClick方法的类中构造一个URLS数组,该方法将URL直接传递给Video类。这在解释中 How do I pass data between Activities in Android application?
Intent intent = new Intent(v.getContext(), Video.class);
intent.putExtra("URL", <insertUrlHere>);
startActivity(intent)
在视频活动中:
Bundle extras = getIntent().getExtras();
if (extras != null) {
String value = extras.getString("URL");
}