android - imageButton onClick is not activating specified method -
i have 2 imagebuttons refer same openthebag method onclick. weird thing can't head around right when click @id/purse imagebutton activates openbug, @id/red_paint doesn't can seen debugger. on earth happening here, please help. here piece of xml.
<framelayout android:id="@+id/frame" android:layout_weight="1.0" android:layout_width="match_parent" android:layout_height="0dip" android:background="@drawable/shelf_wall"> <imagebutton android:id="@+id/purse" android:layout_width="67dp" android:layout_height="82dp" android:layout_gravity="right" android:contentdescription="@string/bag" android:onclick="openthebag" android:scaletype="fitcenter" android:src="@drawable/purse" android:background="@null" /> <imagebutton android:id="@+id/red_paint" android:layout_width="75dp" android:layout_height="112dp" android:layout_gravity="right" android:layout_marginright="10dp" android:layout_margintop="170dp" android:contentdescription="@string/red_paint" android:onclick="openthebag" android:src="@drawable/kyzyl_paint" android:scaletype="fitcenter" android:adjustviewbounds="true" android:background="@null" /> </framelayout>
here method openthebag():
public void openthebag(view view) { relativelayout storage = (relativelayout)this.findviewbyid(r.id.storage); storage.setvisibility(view.visible); }
if @id/storage relevant:
<relativelayout android:id="@+id/storage" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:visibility="gone" > <imagebutton android:id="@+id/imagebutton07" android:layout_width="55dp" android:layout_height="55dp" android:layout_alignleft="@+id/square1" android:layout_aligntop="@+id/imagebutton03" android:adjustviewbounds="true" android:alpha=".4" android:src="@drawable/transparent_background" /> <imagebutton android:id="@+id/imagebutton04" android:layout_width="55dp" android:layout_height="55dp" android:layout_alignleft="@+id/imagebutton01" android:layout_aligntop="@+id/imagebutton07" android:adjustviewbounds="true" android:alpha=".4" android:src="@drawable/transparent_background" /> <imagebutton android:id="@+id/square1" android:layout_width="55dp" android:layout_height="55dp" android:layout_above="@+id/imagebutton03" android:layout_marginleft="11dp" android:layout_torightof="@+id/imagebutton02" android:adjustviewbounds="true" android:alpha=".4" android:src="@drawable/transparent_background" /> <imagebutton android:id="@+id/imagebutton01" android:layout_width="55dp" android:layout_height="55dp" android:layout_aligntop="@+id/square1" android:layout_marginleft="10dp" android:src="@drawable/transparent_background" android:layout_torightof="@+id/square1" android:adjustviewbounds="true" android:onclick="redsplashclicked" /> <imagebutton android:id="@+id/imagebutton05" android:layout_width="55dp" android:layout_height="55dp" android:layout_above="@+id/imagebutton03" android:layout_marginleft="11dp" android:layout_torightof="@+id/imagebutton01" android:adjustviewbounds="true" android:alpha=".4" android:src="@drawable/transparent_background" /> <imagebutton android:id="@+id/imagebutton03" android:layout_width="55dp" android:layout_height="55dp" android:layout_below="@+id/imagebutton02" android:layout_margintop="13dp" android:layout_toleftof="@+id/square1" android:adjustviewbounds="true" android:alpha=".4" android:src="@drawable/transparent_background" /> <imagebutton android:id="@+id/imagebutton09" android:layout_width="55dp" android:layout_height="55dp" android:layout_alignleft="@+id/imagebutton05" android:layout_aligntop="@+id/imagebutton04" android:adjustviewbounds="true" android:alpha=".4" android:src="@drawable/transparent_background" /> <imagebutton android:id="@+id/imagebutton08" android:layout_width="55dp" android:layout_height="55dp" android:layout_aligntop="@+id/imagebutton05" android:layout_centerhorizontal="true" android:adjustviewbounds="true" android:alpha=".4" android:src="@drawable/transparent_background" /> <imagebutton android:id="@+id/imagebutton06" android:layout_width="55dp" android:layout_height="55dp" android:layout_alignleft="@+id/imagebutton08" android:layout_aligntop="@+id/imagebutton09" android:adjustviewbounds="true" android:alpha=".4" android:src="@drawable/transparent_background" /> <imagebutton android:id="@+id/imagebutton02" android:layout_width="55dp" android:layout_height="55dp" android:layout_alignparentleft="true" android:layout_alignparenttop="true" android:layout_marginleft="11dp" android:layout_margintop="10dp" android:adjustviewbounds="true" android:alpha=".4" android:src="@drawable/transparent_background" /> </relativelayout>
why don't try calling event programmatically inside code using onclick()
method. like:
imagebutton mbtnpurse = (imagebutton) findviewbyid(r.id.purse); imagebutton mbtnredpaint = (imagebutton) findviewbyid(r.id.red_paint); mbtnpurse.setonclicklistener(this); mbtnredpaint.setonclicklistener(this);
let activity implement onclicklistener, add unimplemented methods, onclick method:
@override public void onclick(view v) { if(v == mbtnpurse || v == mbtnredpaint) { openthebag(v); } }
and remove android:onclick="openthebag"
both buttons in xml.
Comments
Post a Comment