Recently do a project to use Popupwindow, but in the process of development do not know what the cause of the creation of a good view after the window is always out of play, logcat print the corresponding exception is as follows:
Said is because Popupwindow did not get the focus, so in the Popupwindow layout add android:focusable= "True", the result is still the same exception, make very depressed, formerly Popupwindow has always been so used , and never had any problems.
There is no way to start a variety of search data, the result is not a suitable solution, there is no way since the hint is that the view is not the focus then I added android:focusable= "true" in the sub-element of the popup window, just added after it is not any effect, Because the pop-up window is only used in the grid layout nested TextView, click TextView need to perform the corresponding event, since the play can not come out first write the OnClick method of TextView it, did not expect to write a listener, in the event of triggering pop-up window unexpectedly useful, rude awakening , the original appearance of this exception is because there is no control in the popup window corresponding to the event processing, in the pop-up view to add the corresponding event listener after the entire pop-up box can get the focus, thus processing. This function corresponds to the focusable attribute of the Popupwindow, since it is necessary to get the focus if you want to play the box and interact with it, so how to get the focus without corresponding event handling?
The child view is defined in XML without any problems, but is not a bullet box:
<TextViewAndroid:id= "@+id/tksy"Android:layout_width= "0DP"Android:layout_height= "Wrap_content"Android:layout_weight= "1"android:gravity= "Center"Android:paddingtop= "10DP"Android:paddingbottom= "10DP"android:textsize= "16SP"Android:textcolor= "@color/form_background"Android:text= "@string/tksy"Android:background= "@drawable/textselector" />
After adding the focusable attribute, there is still no response:
<TextViewAndroid:id= "@+id/tksy"Android:layout_width= "0DP"Android:layout_height= "Wrap_content"Android:layout_weight= "1"android:gravity= "Center"Android:paddingtop= "10DP"Android:paddingbottom= "10DP"android:textsize= "16SP"Android:textcolor= "@color/form_background"Android:text= "@string/tksy"Android:background= "@drawable/textselector"android:focusable= "true" />
Finally, after adding the corresponding onclick listener, the popup box can bounce out and be able to use the corresponding defined selector, but the other TextView without the listener event are not using selector effect.
Attributes that must be added when attaching a Popupwindow definition:
New Popupwindow (Layout, layoutparams.match_parent, layoutparams.wrap_content);p opupwindow.setfocusable ( True); When the value is false, clicking outside the window window will not disappear, even if setting the background is not valid, can only be closed by dismiss () popupwindow.setoutsidetouchable (true) ; The outer tap is valid only if the value is set to True Popupwindow.update ();p opupwindow.setbackgrounddrawable (new Bitmapdrawable ());//Only after setting the background in focsable is true when clicking on the outside of the pop-up box will disappear, Popupwindow.showasdropdown (menu);
Android Popupwindow can't bounce.