https://github.com/tony10toes/Supporter2
我有一个youtube视频的数组列表。当用户点击视频时,我希望它在新窗口中打开。我在ArrayList中的Url上收到错误 [错误信息] [1]
和 如何在新窗口中打开它?我已经设置了一个onclick监听器,但我对如何使用该位置显示所选的YouTube视频感到困惑
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
// Get the {@link Video} object at the given position the user clicked on
Video currentVideo = videos.get(position);
currentVideo.equals(currentVideo.getVideoResourceUrl());
Intent storiesIntent = new Intent(StoriesActivity.this, VideoActivity.class);
startActivity(storiesIntent);
来自视频活动
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video);
youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
youTubeView.initialize(Config.YOUTUBE_API_KEY, this);
}
@Override
public void onInitializationSuccess(Provider provider, YouTubePlayer player, boolean wasRestored) {
if (!wasRestored) {
player.cueVideo("Ju67yUUVnts"); // Hard coded because I cant figure out how to get the url string in here
}
}
来自视频适配器
public class VideoAdapter extends ArrayAdapter<Video> {
/** Resource ID for the background color for this list of Videos */
private int mColorResourceId;
public VideoAdapter(Context context, ArrayList<Video> Videos, int colorResourceId) {
super(context, 0, Videos);
mColorResourceId = colorResourceId;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Check if an existing view is being reused, otherwise inflate the view
View listItemView = convertView;
if (listItemView == null) {
listItemView = LayoutInflater.from(getContext()).inflate(
R.layout.list_item, parent, false);
}
// Get the {@link Video} object located at this position in the list
Video currentVideo = getItem(position);
// Find the TextView in the list_item.xml layout with the ID default_text_view.
TextView descriptionTextView = (TextView) listItemView.findViewById(R.id.description_text_view);
// Get the default translation from the currentWord object and set this text on
// the default TextView.
descriptionTextView.setText(currentVideo.getDescriptionVideoId());
// Find the ImageView in the list_item.xml layout with the ID image.
ImageView imageView = (ImageView) listItemView.findViewById(R.id.image);
// Check if an image is provided for this word or not
if (currentVideo.hasImage()) {
// If an image is available, display the provided image based on the resource ID
imageView.setImageResource(currentVideo.getImageResourceId());
// Make sure the view is visible
imageView.setVisibility(View.VISIBLE);
} else {
// Otherwise hide the ImageView (set visibility to GONE)
imageView.setVisibility(View.GONE);
}
// Set the theme color for the list item
View textContainer = listItemView.findViewById(R.id.text_container);
// Find the color that the resource ID maps to
int color = ContextCompat.getColor(getContext(), mColorResourceId);
// Set the background color of the text container View
textContainer.setBackgroundColor(color);
// Return the whole list item layout (containing 2 TextViews) so that it can be shown in
// the ListView.
return listItemView;
}}
Stack溢出很新。在此先感谢