`

popupWindow

PHP 
阅读更多
转载自:http://www.eoeandroid.com/viewthread.php?tid=10850&highlight=popup%2Bwindow

public class popWindow extends Activity {
    /** Called when the activity is first created. */
       
        Button button_show;
        View contentView;
        PopupWindow pWindow;
       
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       
        setContentView(R.layout.main);
       
        button_show=(Button)findViewById(R.id.show_popwindow);
                contentView=View.inflate(popWindow.this, R.layout.pwcontent, null);
               
                contentView.setBackgroundDrawable(getResources().getDrawable(R.drawable.fantasy_pictuer_06));
                contentView.setOnClickListener(new View.OnClickListener() {
                       
                        public void onClick(View v) {
                                // TODO Auto-generated method stub
                                pWindow.dismiss();
                        }
                });
               
                pWindow=new PopupWindow(contentView);
                pWindow.setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
               
        button_show.setOnClickListener(new View.OnClickListener() {
                       
                        public void onClick(View v) {
                                // TODO Auto-generated method stub
                               
                                try {
                                       
                                        if(pWindow.isShowing())
                                        {
                                                pWindow.dismiss();
                                        }
                                       
                                        pWindow.showAsDropDown(v);
                                        pWindow.setFocusable(true);
                                       
                                       
                                } catch (Exception e) {
                                        Toast.makeText(popWindow.this, e.getMessage(), Toast.LENGTH_SHORT);
                                }
                               
                        }
                });
    }
   
   
}
分享到:
评论
1 楼 icoo1985 2011-01-26  
我照着博主的例子做了下,contentView的点击监听事件没有执行,点pWindow没有关闭,请问楼主的contentView的点击事件执行了吗?

相关推荐

Global site tag (gtag.js) - Google Analytics