Android - 按钮问题

发布于 2024-09-16 18:37:59 字数 590 浏览 12 评论 0原文

我终于让我的图像按钮在 ImageView 中工作,按下它后,它就工作了,但紧接着,它停止运行,我收到关闭它的错误消息。 我添加了 onClick 并将其集中在 XML 中,以便它可以在图像视图中工作,但这就是我所得到的。 /drawable文件夹中的按钮是imagebutton选择器代码: http://developer.android.com/reference/android/widget/ImageButton。 html

 <ImageView
 android:onClick="true"
 android:src="@drawable/button"
 android:focusable="true"
 android:layout_height="fill_parent"    
 android:layout_width="fill_parent"
 android:scaleType="fitStart"

我怀疑我忘记了什么......

I finally got my image button to work within an ImageView, and after I press it, it works, but imnmediately after, it stops running and I get the error message to close it.
I added the onClick and focused it in the XML so that it will work within an imageview, but that's all I got. The button in the /drawable folder is the imagebutton selector code:
http://developer.android.com/reference/android/widget/ImageButton.html

 <ImageView
 android:onClick="true"
 android:src="@drawable/button"
 android:focusable="true"
 android:layout_height="fill_parent"    
 android:layout_width="fill_parent"
 android:scaleType="fitStart"

I have a suspicion that I'm forgetting something....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

满地尘埃落定 2024-09-23 18:37:59

是的,第一个用户是对的。错误在于 android:onClick 事件。它不是布尔值。它用于指定当用户单击按钮时应触发的方法的名称。在此处检查此示例,向下滚动到底部并检查他们如何实现此属性。

http://android-developers. blogspot.com/2009/10/ui-framework-changes-in-android-16.html

Yes the first user is right. The mistake is with the android:onClick event. It is not a Boolean value. It is used to specify the name of your method that should be fired when a user clicks on the button. Check this sample here scroll down to the bottom and check how they have implemented this property.

http://android-developers.blogspot.com/2009/10/ui-framework-changes-in-android-16.html

晚雾 2024-09-23 18:37:59

我认为它与 android:onClick 位有关。我从来没有在 XML 中设置过这个(就像你一样);我不确定你是否能做到这一点。

您需要的是 Activity 中使用此 XML 的 onClickListener。检查这个这里

I think it's with the android:onClick bit. I have never set this in XML (like you have); I'm not sure you can even do that.

What you want is an onClickListener in the Activity which uses this XML. Check this here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文