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 );