android - About Image click Issue -
i have question image click issue:
i using parallax effect sticky, in viewpager not working on clicking. requirement if user clicks on that,then should redirect page.i using this link that.
i using viewpager instead of imageview , viewpager has image sliding. thats not working.i getting array of images.
any idea wrong ?
thanks.
code: public class mainactivity extends actionbaractivity { private textview stickyview; private listview listview; private view heroimageview; private view stickyviewspacer; private int max_rows = 20; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); /* initialise list view, hero image, , sticky view */ listview = (listview) findviewbyid(r.id.listview); heroimageview = findviewbyid(r.id.heroimageview); stickyview = (textview) findviewbyid(r.id.stickyview); heroimageview.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { toast.maketext(collectiondetailactivity.this, "click", toast.length_short).show(); } }); /* inflate list header layout */ layoutinflater inflater = (layoutinflater) getsystemservice(context.layout_inflater_service); view listheader = inflater.inflate(r.layout.list_header, null); stickyviewspacer = listheader.findviewbyid(r.id.stickyviewplaceholder); /* add list view header */ listview.addheaderview(listheader); /* handle list view scroll events */ listview.setonscrolllistener(new abslistview.onscrolllistener() { @override public void onscrollstatechanged(abslistview view, int scrollstate) { } @override public void onscroll(abslistview view, int firstvisibleitem, int visibleitemcount, int totalitemcount) { /* check if first item reached top.*/ if (listview.getfirstvisibleposition() == 0) { view firstchild = listview.getchildat(0); int topy = 0; if (firstchild != null) { topy = firstchild.gettop(); } int herotopy = stickyviewspacer.gettop(); stickyview.sety(math.max(0, herotopy + topy)); /* set image scroll half of amount of listview */ heroimageview.sety(topy * 0.5f); } } }); /* populate listview sample data */ list<string> modellist = new arraylist<>(); (int = 0; < max_rows; i++) { modellist.add("list item " + i); } arrayadapter adapter = new arrayadapter(this, r.layout.list_row, modellist); listview.setadapter(adapter); } }
look view hierarchy, listview on imageview , click event handle listview. stickyview on listview. if need handle click event imageview can use click event space item(list_header layout) of listview.
change :
heroimageview.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { toast.maketext(collectiondetailactivity.this, "click", toast.length_short).show(); } }); code :
stickyview.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { toast.maketext(mainactivity.this, "stickyview clicked", toast.length_short).show(); } }); and add handle click event of imageview :
listview.setonitemclicklistener(new adapterview.onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view, int position, long id) { if (position == 0) { toast.maketext(mainactivity.this, "heroimageview clicked", toast.length_short).show(); } else { //listview item clicked } } });
Comments
Post a Comment