I have a list of videos and on each video view I have an icon, I'm trying to make that when the user clicks on the icon, It would add the video to another activity (Sending the video's data), the problem is that for that I need to call a method from another method (From OnClick to OnItemClick) and I can't because I don't have all the parameters I need.
OnClick:
@Override
public void onClick(View v) {
switch (v.getId()){
//Case the search button was clicked.
case R.id.yt_video_btn:
try {
final String keyWord = mVideoEdt.getText().toString().trim();
hideKeyboard();
if (keyWord.length() > 0) {
AppUtils.showToast(AppConstants.SEARCH_VIDEO_MSG);
AppUtils.showToast(AppConstants.DIALOG_TITLE);
mServiceTask = new ServiceTask(SEARCH_VIDEO);
mServiceTask.setmServerResponseListener(this);
mServiceTask.execute(new Object[]{keyWord});
} else {
AppUtils.showToast("Empty filed");
}
}catch (Exception e){}
break;
//TODO: when add_favorite clicked, send details of video to Favorites activity, and show it there.
//Case the star symbol was clicked.
case R.id.add_favorite:
AppUtils.showToast("Added to favorites");
}
}
OnItemClick:
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
SearchResult result = (SearchResult)parent.getItemAtPosition(position);
VIDEO_ID = result.getId().getVideoId();
Intent videoIntent = YouTubeStandalonePlayer.createVideoIntent(this, AppConstants.KEY, VIDEO_ID);
startActivity(videoIntent);
}
I need to send the SearchResult from onItemClick if case 2 in onClick is activated.
Hope you guys understood me, sorry for bad English and thanks in advance!
SearchResult:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder mHolder;
if(convertView != null){
mHolder = (ViewHolder)convertView.getTag();
}else{
mHolder = new ViewHolder();
convertView = mLayoutInflater.inflate(R.layout.view_video_item,null);
mHolder.mVideoThumbnail = (ImageView)convertView.findViewById(R.id.video_thumbnail);
mHolder.mVideoTitle = (TextView)convertView.findViewById(R.id.video_title);
convertView.setTag(mHolder);
}
//Setting the data
SearchResult result = mVideoList.get(position);
mHolder.mVideoTitle.setText(result.getSnippet().getTitle());
//Loading the image
Picasso.with(mActivity).load(result.getSnippet().getThumbnails().getMedium().getUrl()).into(mHolder.mVideoThumbnail);
return convertView;
}