2017-05-31 4 views
0

Je ne peux pas filtrer listview qui est à l'intérieur d'un Popupwindow.android - filtre listview inside popupwindow

Il échoue avec une exception

android.view.WindowManager$BadTokenException: Unable to add window -- token [email protected] is not valid; is your activity running? 
    at android.view.ViewRootImpl.setView(ViewRootImpl.java:679) 
     at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:342) 
     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93) 
     at android.widget.PopupWindow.invokePopup(PopupWindow.java:1378) 
     at android.widget.PopupWindow.showAtLocation(PopupWindow.java:1154) 
     at android.widget.PopupWindow.showAtLocation(PopupWindow.java:1121) 
     at android.widget.AbsListView.positionPopup(AbsListView.java:5665) 
     at android.widget.AbsListView.showPopup(AbsListView.java:5651) 
     at android.widget.AbsListView.onTextChanged(AbsListView.java:6095) 
     at android.widget.TextView.sendOnTextChanged(TextView.java:8187) 
     at android.widget.TextView.setText(TextView.java:4483) 
     at android.widget.TextView.setText(TextView.java:4337) 
     at android.widget.EditText.setText(EditText.java:89) 
     at android.widget.TextView.setText(TextView.java:4312) 
     at android.widget.AbsListView.setFilterText(AbsListView.java:1944) 

I afficher le popupWindow comme:

popupWindow.showAtLocation(getWindow().getDecorView(), Gravity.CENTER, 0, 0); 

Popup mise en page est

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
    <EditText 
     android:hint="" /> 
    <ListView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
    </ListView> 
</RelativeLayout> 

Pouvez-vous fournir des pointeurs?

+0

fournissez le code de votre adaptateur pour listview? –

+0

J'ai résolu ce problème en utilisant la boîte de dialogue à la place de popupwindow – GJain

Répondre

0

Je pense que le problème est que vous montrez votre popup est montré trop tôt. Utilisez showatlocation dans runnable comme ci-dessous

new Handler().postDelayed(new Runnable(){ 
    public void run() { 
     pwindow.showAtLocation(popupView, Gravity.CENTER, 0, 0); 
    } 
}, 100L); 
+0

Le problème est le filtrage de liste dans la fenêtre contextuelle. Je suis capable de montrer popup. Mais quand le filtrage de liste arrive, il essaie d'afficher un autre popup qui déclenche une exception. – GJain

+0

Essayez d'utiliser runnable si cela fonctionne ou sinon poster votre code, va résoudre le problème. –