Hi all,

I want to intercept the OnTouch event in a PopupWindow, but it failes
everytime. Here is the code snip:

public class Demo extends Activity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);

                // Prepare the popup window
                final TextView popupText = new TextView(this);
                popupText.setText("Poping up...");
                popupText.setBackgroundColor(Color.BLUE);
                popupText.setFocusableInTouchMode(true);
                
                final PopupWindow popupWindow = new PopupWindow(this);
                popupWindow.setContentView(popupText);
                popupWindow.setWidth(100);
                popupWindow.setHeight(100);
                popupWindow.setBackgroundDrawable(null);
                popupWindow.setOutsideTouchable(true);
                popupWindow.setTouchInterceptor(new OnTouchListener() {

                        public boolean onTouch(View v, MotionEvent event) {
                                Log.d("Demo", "popupWindow::onTouch >>> view: " 
+ v + ", event: " + event);
                                return false;
                        }
                        
                });
                
                // Prepare the activity view
                final LinearLayout layout = new LinearLayout(this);
                layout.setOrientation(LinearLayout.VERTICAL);
                layout.setOnTouchListener(new OnTouchListener() {

                        public boolean onTouch(View v, MotionEvent event) {
                                Log.d("Demo", "layout::onTouch >>> view: " + v 
+ ", event: " + event);
                                return false;
                        }
                        
                });

                final TextView backgroundView = new TextView(this);
                backgroundView.setWidth(240);
                backgroundView.setHeight(300);
                backgroundView.setBackgroundColor(Color.RED);
                layout.addView(backgroundView);
                
                final Button button = new Button(this);
                button.setWidth(240);
                button.setHeight(20);
                button.setOnClickListener(new OnClickListener() {

                        public void onClick(View v) {
                                popupWindow.showAsDropDown(backgroundView);
                        }
                        
                });
                layout.addView(button);

                setContentView(layout);
        }

When the activity started, I can click the button to show the popup
window correctly. But after that, nothing happens when I touch the
popup window's view. But if I touch any where outside the popup
window, the log
Log.d("Demo", "layout::onTouch >>> view: " + v + ", event: " + event);
will work.

It looks like when I touch the view of the popup window, the touch
event has been consumed somewhere?

Do you have any ideas on this? Thanks for your consideration.

Regards,
Johnny
-- 
we all have our crosses to bear

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to