android - How to get value of current array adapter position other than in getView -
i using cardstack through array adapter. using getter setters display data on card. getting duration of song associated card getsongduration(). problem when loads , in getview method do:
songduration = item.getsongduration();
and log value, being called multiple times different positions.
i need value song duration current song. use notify dataset changed instance not see how applies.
this adapter:
public class songpreviewcardsdataadapter extends arrayadapter<songdatabasemappingadapter> { private context mcontext; public songpreviewcardsdataadapter(context context, int resource) { super(context, resource); mcontext = context; } imagebutton onestarrating; imagebutton twostarrating; imagebutton threestarrating; imagebutton fourstarrating; imagebutton fivestarrating; @override public int getcount() { return super.getcount(); } @override public view getview(int position, final view contentview, viewgroup parent) { // initialise song views final songdatabasemappingadapter item = getitem(position); long songduration = item.getsongduration(); log.d ("duration", ""+songduration); textview songname = (textview) (contentview.findviewbyid(r.id.songnametextview)); textview artist_albumname = (textview) (contentview.findviewbyid(r.id.artist_albumview)); com.mikhaellopez.circularimageview.circularimageview songimage = (circularimageview) contentview.findviewbyid(r.id.songimageview); string imageurl = (item.getpictureurl()); picasso .with(this.getcontext()) .load(imageurl) .into(songimage); final circularprogressbar circularprogressbar = (circularprogressbar)contentview.findviewbyid(r.id.songprogresswheel); circularprogressbar.setcolor(contextcompat.getcolor(getcontext(), r.color.darkred)); circularprogressbar.setbackgroundcolor(contextcompat.getcolor(getcontext(), r.color.darkbluegrey)); circularprogressbar.setprogressbarwidth(10); circularprogressbar.setbackgroundprogressbarwidth(10); com.mikhaellopez.circularimageview.circularimageview imagelocked = (circularimageview) contentview.findviewbyid(r.id.lockedimageview); // initialise rating buttons onestarrating = (imagebutton) contentview.findviewbyid(r.id.ratingbutton1); twostarrating = (imagebutton) contentview.findviewbyid(r.id.ratingbutton2); threestarrating = (imagebutton) contentview.findviewbyid(r.id.ratingbutton3); fourstarrating = (imagebutton) contentview.findviewbyid(r.id.ratingbutton4); fivestarrating = (imagebutton) contentview.findviewbyid(r.id.ratingbutton5); if (item.getonestarrating()) { onestarrating.setimageresource(r.drawable.starfullnew); imagelocked.setvisibility(contentview.gone); artist_albumname.settext(item.getartist() + " - " + item.getalbumtitle()); songname.settext(item.getsongtitle()); onestarrating.setclickable(false); twostarrating.setclickable(false); threestarrating.setclickable(false); fourstarrating.setclickable(false); fivestarrating.setclickable(false); } if (item.gettwostarrating()) { onestarrating.setimageresource(r.drawable.starfullnew); twostarrating.setimageresource(r.drawable.starfullnew); imagelocked.setvisibility(contentview.gone); artist_albumname.settext(item.getartist() + " - " + item.getalbumtitle()); songname.settext(item.getsongtitle()); onestarrating.setclickable(false); twostarrating.setclickable(false); threestarrating.setclickable(false); fourstarrating.setclickable(false); fivestarrating.setclickable(false); } if (item.getthreestarrating()) { onestarrating.setimageresource(r.drawable.starfullnew); twostarrating.setimageresource(r.drawable.starfullnew); threestarrating.setimageresource(r.drawable.starfullnew); imagelocked.setvisibility(contentview.gone); artist_albumname.settext(item.getartist() + " - " + item.getalbumtitle()); songname.settext(item.getsongtitle()); onestarrating.setclickable(false); twostarrating.setclickable(false); threestarrating.setclickable(false); fourstarrating.setclickable(false); fivestarrating.setclickable(false); } if (item.getfourstarrating()) { onestarrating.setimageresource(r.drawable.starfullnew); twostarrating.setimageresource(r.drawable.starfullnew); threestarrating.setimageresource(r.drawable.starfullnew); fourstarrating.setimageresource(r.drawable.starfullnew); imagelocked.setvisibility(contentview.gone); artist_albumname.settext(item.getartist() + " - " + item.getalbumtitle()); onestarrating.setclickable(false); twostarrating.setclickable(false); threestarrating.setclickable(false); fourstarrating.setclickable(false); fivestarrating.setclickable(false); } if (item.getfivestarrating()) { onestarrating.setimageresource(r.drawable.starfullnew); twostarrating.setimageresource(r.drawable.starfullnew); threestarrating.setimageresource(r.drawable.starfullnew); fourstarrating.setimageresource(r.drawable.starfullnew); fivestarrating.setimageresource(r.drawable.starfullnew); imagelocked.setvisibility(contentview.gone); artist_albumname.settext(item.getartist() + " - " + item.getalbumtitle()); songname.settext(item.getsongtitle()); onestarrating.setenabled(false); twostarrating.setenabled(false); threestarrating.setenabled(false); fourstarrating.setenabled(false); fivestarrating.setenabled(false); } onestarrating.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { log.d("star", "star clicked"); item.setonestarrating(true); notifydatasetchanged(); } }); twostarrating.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { log.d("star", "star clicked"); item.settwostarrating(true); notifydatasetchanged(); demopreviewsongfragment.userhasratedsong = true; } }); threestarrating.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { log.d("star", "star clicked"); item.setthreestarrating(true); notifydatasetchanged(); demopreviewsongfragment.userhasratedsong = true; } }); fourstarrating.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { log.d("star", "star clicked"); item.setfourstarrating(true); notifydatasetchanged(); demopreviewsongfragment.userhasratedsong = true; } }); fivestarrating.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { log.d("star", "star clicked"); item.setfivestarrating(true); notifydatasetchanged(); demopreviewsongfragment.userhasratedsong = true; } }); return contentview; } }
Comments
Post a Comment