android - How to determine which View was clicked in a ListView with custom layout -
i have custom listview
has custom layout couple of views. can check in method onitemclick()
of these views clicked? searched , found 1 explanation couldn't me lot.
here custom view:
@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); mholder.mvideofavorite = (imageview)convertview.findviewbyid(r.id.video_favorite); convertview.settag(mholder); } //setting data searchresult result = mvideolist.get(position); mholder.mvideotitle.settext(result.getsnippet().gettitle()); //loading image picasso.with(mactivity).load(result.getsnippet().getthumbnails().getmedium().geturl()).into(mholder.mvideothumbnail); return convertview; } private class viewholder{ private textview mvideotitle = null; private imageview mvideothumbnail = null; //testing private imageview mvideofavorite = null; }
i need know if mvideofavorite
clicked in method:
@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); }
any ideas how this?
basically, have is, make imageview capture onclick events set xml value :
android:clickable="true"
after set in custom layout imageview called "mvideofavorite", must implement onclick method follow inside getview method custom adapter:
@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); mholder.mvideofavorite = (imageview)convertview.findviewbyid(r.id.video_favorite); mholder.mvideofavorite.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub // stuff } }); convertview.settag(mholder); } //setting data searchresult result = mvideolist.get(position); mholder.mvideotitle.settext(result.getsnippet().gettitle()); //loading image picasso.with(mactivity).load(result.getsnippet().getthumbnails().getmedium().geturl()).into(mholder.mvideothumbnail); return convertview; }
basically have @ all. regards,
Comments
Post a Comment