开发者

Make a ViewGroup clickable on Android

开发者 https://www.devze.com 2023-01-07 06:38 出处:网络
I have a ViewGroup (LinearLayout) which contains a couple of TextViews and one ImageView. I want to make this entire group clickable.

I have a ViewGroup (LinearLayout) which contains a couple of TextViews and one ImageView. I want to make this entire group clickable.

I tried something like this:

    viewGroup.setOnClickListener( new OnClickListener(){
        @Override
        public void onClick() {
        开发者_JAVA百科    //do stuff
        }
    });

However, clicks on the TextViews or ImageViews or on the area enclosed by the ViewGroup above doesn't result in the handler being called.

Any suggestions on how I can make a whole ViewGroup clickable?


Solution was as simple as adding

android:clickable="true"

to the xml for the RelativeLayout group


Make the layout click-able. You can make the layout clickable (you might have to use the focus attributes). Just don't forget to assign an ID to the layout so you can detect it.

0

精彩评论

暂无评论...
验证码 换一张
取 消