java Android 中 ImageButton 上的 ClickEvent?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2386402/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ClickEvent on ImageButton in Android?
提问by harish
Is it possible to add a click event to an ImageButton?
是否可以向 ImageButton 添加单击事件?
回答by Hassy31
Yes it is! you can implement the onclick method like this
是的!你可以像这样实现 onclick 方法
ImageButton ib = (ImageButton)findViewById(R.id.imageButton);
ib.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.v("ImageButton", "Clicked!");
}
});
pls read documentationfor further details
请阅读文档以获取更多详细信息
回答by CommonsWare
Yes, it is possible. Here is a sample projectdemonstrating a View.OnClickListenerapplied to an ImageButton.
对的,这是可能的。这是一个示例项目,演示了View.OnClickListener应用于ImageButton.
回答by pfgrid
Yes, it is possible, here is the sample code (and zip-file)
是的,这是可能的,这是示例代码(和 zip 文件)
http://www.codegod.de/WebAppCodeGod/Android-ImageButtons-in-ListView-with-RelativeLayout-AID589.aspx
http://www.codegod.de/WebAppCodeGod/Android-ImageButtons-in-ListView-with-RelativeLayout-AID589.aspx

