android - Access Button's LinearLayout through its OnClickListener -
i have few buttons
in linearlayout
. both dynamically created. there way can access linearlayout
through button
? set linearlayouts
id's
0 or 1. want buttons if in linearlayout
equal 1.
code:
linearlayout linearlayout = new linearlayout(view.getcontext()); linearlayout.setid(1); button dynamicbuttons = new button(view.getcontext()); ... ... ... linearlayout.addview(dynamicbuttons, layoutparam);
so added button
linearlayout
. can button's
onclicklistener
:
dynamicbuttons.setonclicklistener( new view.onclicklistener() { public void onclick(view view) { if (dynamicbutton.getparentview().getid()==1){ //when click button, want access linearlayout button in //do } } });
of course line dynamicbutton.getparentview().getid()==1
wrong. how can access button's
linearlayout?
you on right track. need cast linear layout.
dynamicbuttons.setonclicklistener( new view.onclicklistener() { public void onclick(view view) { linearlayout ll = (linearlayout) dynamicbuttons.getparent(); if (ll.getid()==1){ //when click button, want access linearlayout button in //do } } });
Comments
Post a Comment