Android - 按钮问题
我终于让我的图像按钮在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,第一个用户是对的。错误在于
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
我认为它与
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