2

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

在此处输入图像描述

我的主要课程如下

 @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? 

提前致谢

4

2 回答 2

1

如果你不把它当作一个窗口怎么办。让它成为行本身的隐藏元素。显示/隐藏它,由于简单的子顺序,它将覆盖它之前的行。这使您可以完全控制其外观,也使您能够避免与花哨的弹出黑客作斗争。

于 2013-11-30T01:15:40.513 回答
0

我认为您可以隐藏/显示第二个弹出窗口,而不是将其用作弹出窗口,您可以将其添加到第一个弹出窗口布局中,但在需要之前将其隐藏。

于 2013-10-17T13:00:22.923 回答