I have a class which is not Activity and an Activity. I have an onClick method and I want to pass from this onClick method an Object to the Activity. I can't use PutExtra because of this: MainActivity, Favorites, YtAdapter
I'm opening the Favroties class from MainActivity, but need to send from YtAdapter to Favorites. Hope this is understandable.
YtAdapter:
@Override
public View getView(final int position, View convertView, final 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);
mHolder.mVideoFavorite = (ImageView)convertView.findViewById(R.id.video_favorite);
convertView.setTag(mHolder);
}
//Setting the data
final 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);
//OnClickListeners
mHolder.mVideoFavorite.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//////////////////////////////////////////////////////////////
// Need to send SearchResult result from here to favorites //
////////////////////////////////////////////////////////////
AppUtils.showToast(result.getSnippet().getTitle() + " Was added to favorites.");
}
});
mHolder.mVideoThumbnail.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AppUtils.showToast("Please click on title to start video");
}
});
return convertView;
}
Aucun commentaire:
Enregistrer un commentaire