Frage

enter image description hereI have made a custom popup in an app where the layout of the popup is as follows:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

    <ScrollView 
        android:id="@+id/scroller"
        android:layout_margin="4dp"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/popup3"
        android:fadingEdgeLength="0dip"
        android:scrollbars="none">

        <LinearLayout
            android:id="@+id/tracks"
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:padding="8dip"/>

    </ScrollView >


    <Button
        android:id="@+id/popup_closer"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:clickable="true"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:layout_below="@id/scroller"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="0dip"
        android:layout_marginLeft="0dip"
        android:background="@drawable/close_popup"
        android:text=" X " />   
</RelativeLayout>

In the "tracks"(LinearLayout) I add a webview, now in my code I add OnClick event listener on the button in this Layout, but it never works, I added a Log.i("clicked","...."); to check if the onclick fires but it doesn't

Additional info:

the popup window has the following :

mWindow.setTouchable(true);
mWindow.setFocusable(true);
mWindow.setOutsideTouchable(true);
mWindow.setContentView(mRootView); // mRootView is the inflated layout above.

The full code for the popup is here :

http://pastebin.com/6UQRRJq4

and the Extended class is here:

http://pastebin.com/BFb3e6MG

Notice: this is a modified version of "QuickAction dialog"

Here's how my popup looks like (If there's another way to have the same layout) and be able to click on that small circular button It'd be great)

UPDATE: I found the problem in my code it was here :

View rootView = mInflater.inflate(R.layout.popup_fullscreen,null);
final Button b = (Button) rootView.findViewById(R.id.popup_closer

I should've used the same instance of the inflated view instead of inflating new view;

i.e the correct code is:

// Changed the View rootView .....etc  to mRootView;
final Button b = (Button) mRootView.findViewById(R.id.popup_closer

Now I have another problem: I have to touch the button 2 times to make it work it seems that the first touch event is consumed by the popup or WebView then the second time works.

War es hilfreich?

Lösung

Just a wild guess, but instead of

View rootView = mInflater.inflate(R.layout.popup_fullscreen,null);
final Button b = (Button) rootView.findViewById(R.id.popup_closer);

do

final Button b = (Button) mRootView.findViewById(R.id.popup_closer);

Andere Tipps

Remove mWindow.setOutsideTouchable(true), and leave the rest:

mWindow.setTouchable(true);
mWindow.setFocusable(true);
mWindow.setContentView(mRootView); // mRootView is the inflated layout above.

This should allow your PopupWindow to receive touch events, so they get forwarded to the button. Also, make sure you aren't doing any of this after the window has been shown. This must all be called beforehand.

HTH

first inflate the popup layout over the main layout. create a popupwindow object and then iniside your onclicklistener use the function showasdropdown to display your popupwindow.

Sample given below

View popuplayout=LayoutInflater.from(getApplicationContext()).inflate(R.layout.popup_layout, null, false); PopUpWindow pw = new PopupWindow(popuplayout,260,90,true); pw.showAsDropDown(buttonid, x-coordinate, y-coordinate);

this hould display your popup

Are you confirm that you are going to inflate the right Layout during runtime and getting click on the right button ?

As i have seen your code, you are going to inflate two xml file based on the orientation.

code:

  if (mOrientation == HORIZONTAL) {
        setRootViewId(R.layout.popup_horizontal);
        mAnimStyle  = ANIM_AUTO;
        mChildPos   = 0;
    }
    else if(mOrientation == FULLSCREEN){
            setRootViewId(R.layout.popup_fullscreen);
            mAnimStyle      = ANIM_REFLECT;
        mChildPos   = 0;
    }
    else {
        setRootViewId(R.layout.popup_notifications);
        mAnimStyle  = ANIM_AUTO;
        mChildPos   = 0;
    }

Now, Please check this are you clicking on the right button or clicking on the another layout's close button.

be sure with the managing layout and inflating it.

Hope you got my point.

Feel free for any comments.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top