There are a couple of pictures with links, I want a specific video to open by clicking on them.
I process pressing as follows
viewHolder.photo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String id = ""; Intent appIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:" + id)); Intent webIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=" + id)); try { context.startActivity(appIntent); } catch (ActivityNotFoundException ex) { context.startActivity(webIntent); } Only here the whole thing in id seems to me ... how is it possible to pull out by pressing correctly if the links are different every time? It should be used for several videos, but not for one link.
adapter code
public class ImageAdapter extends BaseAdapter { private Context context; List<ImageUpload> imageUploads; int resource; public ImageAdapter(Context context, List<ImageUpload> imageUploads, int resource) { this.context = context; this.imageUploads = imageUploads; this.resource = resource; } public View getView(final int position, View convertView, final ViewGroup parent) { final GridHolder viewHolder; if (convertView == null) { viewHolder = new GridHolder(); LayoutInflater inflater1 = LayoutInflater.from(context); if (imageUploads.get(position).getOutputMetadata().getFilename().equals("null")) { convertView = inflater1.inflate(R.layout.item_upload_default, parent, false); } else { convertView = inflater1.inflate(R.layout.item_upload, parent, false); } viewHolder.photo = (ImageView) convertView.findViewById(R.id.iv_upload); viewHolder.closeView = (ImageView) convertView.findViewById(R.id.photo_close_btn); viewHolder.progress = (ProgressWheel) convertView.findViewById(R.id.loader_photo); convertView.setTag(viewHolder); } else { viewHolder = (GridHolder) convertView.getTag(); } if (imageUploads.get(position).getOutputMetadata().getFilename().equals("null")) { viewHolder.photo.setImageResource(resource); } else { ImageUpload mobile = imageUploads.get(position); if (imageUploads.get(position).isLoadImage()) if (TextUtils.isEmpty(mobile.getOutputMetadata().getVideoUrl())) Picasso.with(context) .load(StringUtil.URLADS_THUMBLER_RESIZE + 150 + "x" + 150 + "/" + StringUtil.URLADS_THUMBLER_IMAGE + mobile.getOutputMetadata().getFilename()) .into(viewHolder.photo, new Callback() { @Override public void onSuccess() { viewHolder.progress.setVisibility(View.GONE); } @Override public void onError() { } }); else { Picasso.with(context).load(mobile.getOutputMetadata().getVideoUrl()).into(viewHolder.photo); viewHolder.progress.setVisibility(View.GONE); } else { File f = new File(imageUploads.get(position).getPath()); Picasso.with(context) .load(f) .into(viewHolder.photo); } viewHolder.closeView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ((GridView) parent).performItemClick(v, position, 0); } }); viewHolder.photo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String id = ""; String expression = ""; if (id != null && id.trim().length() > 0 && id.matches(".*\\byoutube\\b.*")) { expression = "^.*((youtu.be" + "\\/)" + "|(v\\/)|(\\/u\\/w\\/)|(embed\\/)|(watch\\?))\\??v?=?([^#\\&\\?]*).*"; Intent appIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:" + id)); Intent webIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=" + id)); try { context.startActivity(appIntent); } catch (ActivityNotFoundException ex) { context.startActivity(webIntent); } } ); } return convertView; }