Popupwindow places the listview, and enables the listview to respond to click events. popupwindow

Source: Internet
Author: User

Popupwindow places the listview, and enables the listview to respond to click events. popupwindow

Recently, the function of selecting an avatar is to use a ListView in a Popwindow and a ListView as all albums. Users can click the album in it, then the photo display page will show the photos of the selected album

. At first, we found that the ListView could not obtain the click event. Insert the following code to solve the problem.

popWinPlaylist.setFocusable(true);  popWinPlaylist.update();  

Then I found that the click event cannot be responded to somewhere other than popupwn. In fact, you can use pw (PopupWindow object). getContextView () to get his parent view. Then, the pw loses focus by registering an event for the parent view.

// Configure a processing event outside of focus to listen for parameterPop. getContentView (). setOnTouchListener (new OnTouchListener () {@ Override public boolean onTouch (View v, MotionEvent event) {// TODO Auto-generated method stub parameterPop. setFocusable (false); parameterPop. dismiss (); return true ;}});}

Another problem is found. The return key cannot respond to the click event. I believe the code above should be clear. You can give it to anyone who wants to respond. SetFocusable (true) has enabled Pw to get the focus. Solution: Because ListView is placed in Pw. You can use setOnKeyListener to set the listening code for the ListView in Pw as follows:

parameter_list.setOnKeyListener(new OnKeyListener(){                    @Override                  public boolean onKey(View v, int keyCode, KeyEvent event) {                      // TODO Auto-generated method stub                      parameterPop.dismiss();                      return true;                  }                                });  

In addition, the page under the pop window will not change. We can use the following method to set the background color.

WindowManager. layoutParams lp = getWindow (). getAttributes (); lp. alpha = 0.3f; // you can set the transparency of the bottom window. After dismiss is set, you can get getWindow (). setAttributes (lp );



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.