简体   繁体   English

从LinearLayout中的ImageView中删除onClickListener

[英]Remove onClickListener from ImageView in LinearLayout

I have a LinearLayout with adding some images dynamically with their click listeners. 我有一个LinearLayout ,可以通过点击监听器动态添加一些图像。 When I'm clicking on an ImageView I want to remove Onclick listener from all the ImageViews to prevent clicking on any ImageView again. 当我单击ImageView我想从所有ImageViews删除Onclick侦听器,以防止再次单击任何ImageView

Can anyone suggest any permanent idea without boolean variable. 任何人都可以提出没有boolean变量的任何永久性想法。

将onClickListener设置为null:

imageView.setOnClickListener(null);

You could give your LinearLayout an id, and then loop over all children and set the listener to null; 您可以为您的LinearLayout一个ID,然后遍历所有子项并将侦听器设置为null。

LinearLayout layout = findViewById(R.id.imagesLayout);
View v = null;

for(int i=0; i<layout.getChildCount(); i++) {
    if(v instanceOf ImageView) //you dont have to do this when there are only imageViews
        v.setOnClickListener(null)
}

You can do this like: 您可以这样做:

imageView.setOnClickListener(null);

or 要么

imageView.setClickable(false);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM