如何在android中的另一个弹出窗口中显示弹出窗口

时间:2013-10-17 12:56:52

标签: android popupwindow

我想在另一个弹出窗口中显示弹出窗口,而不是忽略第一个弹出窗口。它看起来像这样

enter image description here

我的主要课程如下

 @Override
public void onClick(View v) {
    // TODO Auto-generated method stub
    location = CommonMethod.locateView(v);
    showMyPresentationPopup(mContext, location);
}

private void showMyPresentationPopup(final Context context, Rect loaction) {
    int popupWidth = convertDipToPixels(400);
    int popupHeight = convertDipToPixels(500);
    String statictext;
    List<String> mResults = new ArrayList<String>();
    for(int i=0;i<15;i++)
    {
        statictext = "Presentatation "+i+" Name Here";
        mResults.add(statictext);
    }
    PresentationListAdapter mAdapter = new PresentationListAdapter(DashboardActivity.this, mResults);

    LayoutInflater layoutInflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     final  View layout = layoutInflater.inflate(R.layout.presentation, null);


    ListView mListView =(ListView)layout.findViewById(R.id.presentationlistid); 
    mListView.setAdapter(mAdapter);
    mListView.setItemsCanFocus(false);
    mListView.setFocusableInTouchMode(false);

    displayPopUp(layout,popupWidth, popupHeight,myPresentation,location);
}
// Creating the PopupWindow
public void displayPopUp(View layout,int popupWidth,int popupHeight,View v, Rect location){
mPresentationList = new PopupWindow(mContext);
mPresentationList.setFocusable(true);
mPresentationList.setContentView(layout);
mPresentationList.setWidth(popupWidth);
mPresentationList.setHeight(popupHeight);
mPresentationList.setTouchable(true);
mPresentationList.setBackgroundDrawable(new BitmapDrawable());
mPresentationList.setOutsideTouchable(true);

 mPresentationList.setTouchInterceptor(new OnTouchListener() {
    public boolean onTouch(View v, MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
            mPresentationList.dismiss();
            return true;
        }
        return false;
    }

});
mPresentationList.showAsDropDown(v, -convertDipToPixels(20), 0);

}

我的getview方法我试图打开另一个弹出窗口

@Override
public View getView(int pos,  View convertview, final ViewGroup arg2) {
    // TODO Auto-generated method stub
    final Viewholder holder;

    if(convertview==null){  
    LayoutInflater layoutInflater =(LayoutInflater)context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
    convertview=layoutInflater.inflate(R.layout.presentationitem, null,false);
    holder=new Viewholder();

    holder.Title=(TextView)convertview.findViewById(R.id.presentationtitle);
    holder.mRefresh=(Button)convertview.findViewById(R.id.refreshid);
    holder.mDelete=(Button)convertview.findViewById(R.id.deleteid);
    holder.mDelete.setFocusable(false);
    holder.mRefresh.setFocusable(false);
    holder.mDelete.setFocusableInTouchMode(false);
    holder.mRefresh.setFocusableInTouchMode(false);


    convertview.setTag(holder);
    }
    else{
        holder=(Viewholder)convertview.getTag();
    }
        Log.e("adapter5453===>",wifilist.get(pos));
        holder.Title.setText(wifilist.get(pos));
        holder.mRefresh.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                int popupWidth = 250;
                int popupHeight = 100;

                LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                View layout = layoutInflater.inflate(R.layout.sync_dialog, null);
                displayRefreshPopUp(layout,popupWidth, popupHeight,v,location);
            }
        });

        convertview.setTag(R.string.close, wifilist.get(pos));
    return convertview;
}

static class Viewholder{

    TextView Title;
    Button mRefresh;
    Button mDelete;


}

public void displayRefreshPopUp(View layout,int popupWidth,int popupHeight,View v, Rect location){
    mRefreshPopUp = new PopupWindow(context);
    mRefreshPopUp.setContentView(layout);
    mRefreshPopUp.setWidth(popupWidth);
    mRefreshPopUp.setHeight(popupHeight);
    mRefreshPopUp.setTouchable(true);
    mRefreshPopUp.setFocusable(true);
    mRefreshPopUp.setBackgroundDrawable(new BitmapDrawable());
    mRefreshPopUp.setOutsideTouchable(true);
    mRefreshPopUp.setTouchInterceptor(new OnTouchListener() {
    public boolean onTouch(View v, MotionEvent event) {
        if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
            mRefreshPopUp.dismiss();
            return true;
        }
        return false;
    }
});
    mRefreshPopUp.showAsDropDown(v, -20, 0);
    //mRefreshPopUp.showAtLocation(v, Gravity.TOP, 0, 0);

}   }

我收到了以下错误。

android.view.WindowManager$BadTokenException: Unable to add window -- token android.view.ViewRootImpl$W@4194d750 is not valid; is your activity running? 

提前致谢

2 个答案:

答案 0 :(得分:1)

如果不将其作为窗口,该怎么办?它是行本身的隐藏元素。显示/隐藏它,并且由于简单的子命令,它将在它之前对行进行分层。这使您可以完全控制其外观,并使您能够避免与花哨的弹出式黑客攻击。

答案 1 :(得分:0)

我认为而不是将其用作POP Up你可以隐藏/显示第二个pop ,您可以在第一个弹出式布局中添加它,但保持隐藏状态直到你需要它。