android - Getting ListView item click position outside of getView() method -
i have listview
:
..and i've been using code handle incoming click events start/stop music playback :
@override public view getview(final int position, view convertview, viewgroup parent) { ... previewbtn.setonclicklistener(new onclicklistener() { @override public void onclick(view view) { boolean istoggled = ((togglebutton) view).ischecked(); mp3file music = getitem(position); if (!istoggled) { callbackactivity.onmusicpreviewstopped(); ((togglebutton) view).setchecked(false); } else { callbackactivity.onmusicpreviewrequested(music); } } }); ...
which works fine tbh. have habit of making class implements required interface instead of creating new 1 every view created.
it'd pretty straight-forward if choose ignore position
of item clicked. sadly, need position
correctly identify mp3file
playing , stop it.
could give me suggestions on how make work?
..or way of doing it?
off top of head i'd suggest set position button tag. implement onclick once class , use v.gettag()
retrieve position of button
@override public view getview(final int position, view convertview, viewgroup parent) { ... previewbtn.settag(position); ... @override public void onclick(view view) { boolean istoggled = ((togglebutton) view).ischecked(); mp3file music = getitem(view.gettag()); if (!istoggled) { callbackactivity.onmusicpreviewstopped(); ((togglebutton) view).setchecked(false); } else { callbackactivity.onmusicpreviewrequested(music); } }
Comments
Post a Comment