android– 包含ImageButton的LinearLayout(带onClick) – 有更好的方法来解决它吗?

android– 包含ImageButton的LinearLayout(带onClick) – 有更好的方法来解决它吗?,第1张

概述目前我有类似的东西:<LinearLayoutandroid:layout_height="80dip"android:id="@+id/linearLayoutSettings"android:layout_width="80dip"android:orientation="vertical"><ImageButtonandroid:layout_height="wra

目前我有类似的东西:

<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附加了onClick侦听器.

问题:在linearLayout内单击Imagebutton时,事件不会被触发.

当我附加到linearLayout时,我可以通过点击这个按钮来解决它.但在这种情况下,它将意味着许多重复代码(有许多按钮).

问题:有没有更有效的方法来解决这个问题?

解决方法:

将以下标记附加到每个图像按钮:
安卓的onClick = “yourOnClickFunction”
然后,在您的活动中,添加相应的功能:

public voID yourOnClickFunction(final VIEw v) {switch(v.getID()) {     //Do whatever is necessary.}}

在switch-block中,您需要了解按钮ID.你可以通过findVIEwByID(R.ID.abutton)获取它们.

总结

以上是内存溢出为你收集整理的android – 包含ImageButton的LinearLayout(带onClick) – 有更好的方法来解决它吗?全部内容,希望文章能够帮你解决android – 包含ImageButton的LinearLayout(带onClick) – 有更好的方法来解决它吗?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1118789.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存