2014-01-06 234 views
0

我有一個使用ArrayAdapter的自定義ListView,它具有處理onClick事件的部分視圖。我已經在下面的代碼中設置它。當用戶點擊視圖時,它會拉起YouTube視頻。我需要知道如何做的是爲每個單獨的視圖點擊播放不同的視頻。這裏是我的代碼自定義ListView使用ArrayAdapter,OnClick事件

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; 
} 


} 

一切正常,我只是我不知道怎麼去當用戶在列表中選擇一個不同的看法不同的視頻播放。

回答

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

蕩那麼簡單。非常感謝,這完美的工作! – Ammonious

0
ss=(String) ((TextView) view).getText(); 

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