FrameLayout click event is not firing
Asked Answered
R

1

13

I have used Framelayour for click event and It was working fine before 2 days but don't know wat happend now it is not working.
Please someone help me.
My code is as below : Design :

<FrameLayout
        android:id="@+id/flWebpre"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1" >

        <WebView
            android:id="@+id/wvWebsite"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />

        <ProgressBar
            android:id="@+id/pbWebsite"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/white"
            android:layout_gravity="center_horizontal" />
    </FrameLayout>

Code :

FrameLayout flWebPre = (FrameLayout) findViewById(R.id.flWebpre);
    flWebPre.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if (isExpanded) {
                isExpanded = false;

                new CollapseAnimation(slidingPanel, panelWidth,
                        TranslateAnimation.RELATIVE_TO_SELF, 0.70f,
                        TranslateAnimation.RELATIVE_TO_SELF, 0.0f, 0, 0.0f,
                        0, 0.0f);
            }
        }
    });
Repetitive answered 7/6, 2013 at 6:46 Comment(1)
I know you already did something but, you forgot to put "clickable" as a parameter in your FrameLayout.Sweetheart
M
26

One easy way is to intercept all touch events. By default, ViewGroup#onInterceptTouchEvent returns false.

You may create a custom layout:

public class ClickableFrameLayout extends FrameLayout {
    private OnClickListener mOnClickListener;

    @Override
    public void setOnClickListener(OnClickListener l) {
        super.setOnClickListener(l);
        mOnClickListener = l;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return mOnClickListener != null;
    }


    // Standard constructors — just pass everything
    public ClickableFrameLayout(final Context context) {
        super(context);
    }

    public ClickableFrameLayout(final Context context, final AttributeSet attrs) {
        super(context, attrs);
    }

    public ClickableFrameLayout(final Context context, final AttributeSet attrs, final int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public ClickableFrameLayout(final Context context, final AttributeSet attrs, final int defStyleAttr, final int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }
}
Millisent answered 8/10, 2014 at 19:14 Comment(2)
yes it is working, but you have forgott the second constructor with AtributeSet...Nomo
Wow, what a perfect solution..!Wileywilfong

© 2022 - 2024 — McMap. All rights reserved.