popupwindow 出错
源代码
public class MenuWindow extends PopupWindow {
private View contentView = null;
public MenuWindow(final Activity context) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(context.LAYOUT_INFLATER_SERVICE);
contentView = inflater.inflate(R.layout.menu_window, null);
// 设置selectpopwindow的view
this.setContentView(contentView);
// 设置selectpopwindow弹出窗体的高
this.setHeight(LayoutParams.WRAP_CONTENT);
// 设置selectpopwindow弹出窗体的宽
this.setWidth(140);
// 设置selectpopwindow弹出窗体可点击
this.setFocusable(true);
this.setOutsideTouchable(true);
// 刷新状态
this.update();
// 实例化一个colordrawable对象,设置颜色半透明
ColorDrawable drawable = new ColorDrawable(0000000000);
// 点back键 和其他地方使其消失,设置这个才能触发ondismisslistener,设置其他控件变化等操作
this.setBackgroundDrawable(drawable);
LinearLayout take = (LinearLayout) contentView
.findViewById(R.id.takelayout);
take.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
MenuWindow.this.dismiss();
}
});
LinearLayout pic = (LinearLayout) contentView
.findViewById(R.id.piclayout);
pic.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
MenuWindow.this.dismiss();
}
});
}
public void ShowMenuWindow(View parent) {
if (!this.isShowing()) {
this.showAsDropDown(parent, 5, 5);
} else {
this.dismiss();
}
}
跳转代码
public class RegisterActivity extends Activity {
private Button btnUpload;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.relayout);
initControl();
btnUpload.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
MenuWindow menu = new MenuWindow(null);
menu.ShowMenuWindow(arg0);
}
});
}
private void initControl() {
btnUpload = (Button) findViewById(R.id.btnUploadpic);
}
}
代码没有显示出错,就是运行时一点击就退出,不知道哪里的问题,哪位救救我啊