i made bitmap button has animation effect on layout cannot find id of layout , says indicates null point
here source below
public class bitmapbutton extends button{ public bitmapbutton(context context) { super(context); init(); } public bitmapbutton(context context, attributeset attrs) { super(context, attrs); init(); } private void init(){ setbackgroundresource(r.drawable.background_selector); setonclicklistener(new onclicklistener() { boolean selected=true; animation anim; linearlayout layout_search = (linearlayout)findviewbyid(r.id.layout_search); @override public void onclick(view v) { if(selected) { setselected(true); anim = animationutils.loadanimation(getcontext(), r.anim.translate_down); ***layout_search.startanimation(anim);*** layout_search.setvisibility(view.visible); selected =!selected; } else{ setselected(false); anim = animationutils.loadanimation(getcontext(), r.anim.translate_up); layout_search.startanimation(anim); layout_search.setvisibility(view.gone); selected =!selected; } } }); } } ========================================================================= layout_search.startanimation(anim);
from here gets wrong saying
java.lang.nullpointerexception: attempt invoke virtual method void android.widget.linearlayout.startanimation(android.view.animation.animation) on null object reference
i know findviewbyid method in button class different 1 in mainactivity dont know then, how can find linearlayout linear_search?? problem can make anim effection on button. plz let me know...
public class bitmapbutton extends button{ public bitmapbutton(context context) { super(context); init(); } public bitmapbutton(context context, attributeset attrs) { super(context, attrs); init(); } private void init(){ setbackgroundresource(r.drawable.background_selector); setonclicklistener(new onclicklistener() { boolean selected=true; animation anim; // _____________ commented out line ______________ // linearlayout layout_search = (linearlayout)v.findviewbyid(r.id.layout_search); @override public void onclick(view v) { // add line here , add view v before findviewbyid linearlayout layout_search = (linearlayout)v.findviewbyid(r.id.layout_search); if(selected) { setselected(true); anim = animationutils.loadanimation(getcontext(), r.anim.translate_down); ***layout_search.startanimation(anim);*** layout_search.setvisibility(view.visible); selected =!selected; } else{ setselected(false); anim = animationutils.loadanimation(getcontext(), r.anim.translate_up); layout_search.startanimation(anim); layout_search.setvisibility(view.gone); selected =!selected; } } }); } }
Comments
Post a Comment