2

I have a PopupWindow on my activity. However, PopupWindow is not dismissed after interacting with my activity.

I want to dismiss the popup when I'm touching/scrolling/clicking/etc on the screen which is not the PopupWindow.

public class ListViewForDeleteContact extends AppCompatActivity {
    ListView myListView;
    protected  void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listviewfordeletecontactlayout_main);

        myListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                LayoutInflater layoutInflater=(LayoutInflater)ListViewForDeleteContact.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                View dfg= layoutInflater.inflate(R.layout.popupwindowfordeletelayout_main,(ViewGroup)findViewById(R.id.popupId));
                PopupWindow popupWindow=new PopupWindow(dfg,420,300,true);

                popupWindow.showAtLocation(dfg, Gravity.CENTER, 0, 0);
                popupWindow.setOutsideTouchable(true);

            }
        });
    }
}

I tried some methods like setOutsideTouchable(true); and setBackgroundDrawable(true) but it did not work for me.

guipivoto
  • 18,327
  • 9
  • 60
  • 75
xyz rety
  • 671
  • 2
  • 11
  • 22

1 Answers1

0
 First add
 popupWindow.setOutsideTouchable(true);
and use 
popupWindow.setBackgroundDrawable(new BitmapDrawable(getResources(),
            ""));
or 

popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {

    @Override
    public void onDismiss() {
        popupWindow.dismiss();

    }
});
Gil Snovsky
  • 210
  • 2
  • 6