简体   繁体   中英

How to dismiss the popup box in the following android code?

In my android application when i clicked a button it shows a popup box but i can't able to dismiss that box by clicking the same button or any else outside the popup box. Here i enclosed my android code for popup function.I tried by adding

m_pw.dismiss();

function but it's too failed.

popup.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v){
            LayoutInflater inflater =(LayoutInflater) ChooseFileActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View layout = inflater.inflate(R.layout.saved,null);
            m_pw = new PopupWindow(layout, 400, 300, true);
            popup(v, layout);
        }


    });

public void popup(View v, View layout){
    if (m_pw.isShowing()) {
        m_pw.dismiss();
    } else {
        m_pw.showAtLocation(layout, Gravity.TOP, -80, 80);


    }
}

This is because the popup window does not respond to onTouch or onKey events unless it has a background that != null.

Check the below links for further clarifiactaion:

Android popup window dismissal

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM