开发者

Make a ViewGroup clickable on Android

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜