Android – linear layout with an imagebutton – is there a better way to solve it?

At present, I have something similar:

<LinearLayout android:layout_height="80dip" android:id="@+id/linearLayoutSettings"
 android:layout_width="80dip" android:orientation="vertical">

    <ImageButton android:layout_height="wrap_content" android:src="@android:drawable/ic_menu_manage" 
android:id="@+id/imageButton1" android:layout_width="wrap_content"></ImageButton>

</LinearLayout>

LinearLayout has an onclick listener attached

Problem: when you click imagebutton in LinearLayout, the event will not be triggered

When I attach to LinearLayout, I can solve it by clicking this button. But in this case, it will mean a lot of duplicate code (there are many buttons)

Question: is there a more effective way to solve this problem?

resolvent:

Attach the following tag to each image button: Android onclick = "youronclickfunction" and then, in your activity, add the corresponding function:

public void yourOnClickFunction(final View v) {
switch(v.getId()) {
     //Do whatever is necessary.
}
}

In switch block, you need to know the button ID. you can get them through findviewbyid (r.id.a button)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>