java - Changing image source of an imageview in a different layout -
i can't find solution anywhere, i'm still quite new programming might simple question.
in mainactivity
take position of viewpager
. according position want change source of imageview
placed in layout inflate in service. code keep getting nullpointerexception
. need declare imageview
differently because it's in different layout showed one?
public void onclick(view view) { pagenumber = viewpager.getcurrentitem(); imageview = (imageview) findviewbyid(r.id.filterview); switch (pagenumber){ case 0: imageview.setimageresource(r.drawable.goghfilter); break; case 1: imageview.setimageresource(r.drawable.background3); break;
thanks help!
well remember class inflated layout find views in layout, try findbyid view not in layout cause errors. resolve this, define custom layout inflater, inflate layout image , used view inflated , perform findbyid on it.
Comments
Post a Comment