0

I have a Custom ListView using Arrayadapter that has a portion of the view for handling the onClick event. I've set it in the code below. when the user clicks the view it will pull up a youtube video. What I need to know how to do is have a different video play for each individual view click. Here is my code

 public class CustomList extends ArrayAdapter<RowItem> {

Context context;
private static final String[] videoId = {"-Uwjt32NvVA", "J7-8IteUvt8", "XjwZAa2EjKA",};

public CustomList(Context context, int resourceId,
        List<RowItem> items) {
    super(context, resourceId, items);
    this.context = context;
}

/*private view holder class*/
private class ViewHolder {
   // ImageView imageView;
    TextView txtTitle;
    TextView txtCareer;
    TextView txtSeason;
    TextView txtGame;
    RelativeLayout highlight;
}

public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder = null;
    RowItem rowItem = getItem(position);

    LayoutInflater mInflater = (LayoutInflater) context
            .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.list_row, null);
        holder = new ViewHolder();
        holder.txtTitle = (TextView) convertView.findViewById(R.id.title);
        holder.txtCareer = (TextView) convertView.findViewById(R.id.career);
        holder.txtSeason = (TextView) convertView.findViewById(R.id.season);
        holder.txtGame = (TextView) convertView.findViewById(R.id.game);
        holder.highlight = (RelativeLayout) convertView.findViewById(R.id.highlight);

        convertView.setTag(holder);
    } else
        holder = (ViewHolder) convertView.getTag();
    holder.txtTitle.setText(rowItem.getTitle());
    holder.txtCareer.setText(rowItem.getCareer());
    holder.txtSeason.setText(rowItem.getSeason());
    holder.txtGame.setText(rowItem.getGame());
    //holder.imageView.setImageResource(rowItem.geturl());

    holder.highlight .setOnClickListener(new OnClickListener() {

        public void onClick(View v) {


            Intent intent = new Intent(Intent.ACTION_VIEW,  Uri.parse("vnd.youtube:"+videoId)); 
            intent.putExtra("VIDEO_ID", videoId); 
            context.startActivity(intent); 

        }
    });

    return convertView;
}


}

Everything works I just am not sure how to get a different video to play when the user selects a different view in the list.

2 Answers 2

1
 Intent intent = new Intent(Intent.ACTION_VIEW,  Uri.parse("vnd.youtube:"+videoId[position])); 
 intent.putExtra("VIDEO_ID", videoId[position]); 
 context.startActivity(intent); 
Sign up to request clarification or add additional context in comments.

1 Comment

Dang so Simple. Thanks so much this worked perfectly!
0
ss=(String) ((TextView) view).getText();

Intent intent = new Intent(Intent.ACTION_VIEW,  Uri.parse("vnd.youtube:"+ss)); 
context.startActivity(intent);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.