//载入listview界面
LayoutInflater inflater = (LayoutInflater) this
.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.task_detail_popupwindow, null);
lvPopupList = (ListView) layout.findViewById(R.id.lv_popup_list);
//添加事件
// TODO Auto-generated method stub
if (pwMyPopWindow != null && pwMyPopWindow.isShowing()) {
pwMyPopWindow.dismiss();
return;
} else {
initPop();
pwMyPopWindow.setWidth(userName.getWidth());
pwMyPopWindow.showAsDropDown(userName, 0, 0);
}
public void initPop() {
// 获取自定义布局文件pop.xml的视图
View mypopupView = getLayoutInflater().inflate(
R.layout.task_detail_popupwindow, null, false);
lvPopupList = (ListView) mypopupView.findViewById(R.id.lv_popup_list);
DisplayMetrics metric = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metric);
int height = metric.heightPixels; // 屏幕高度(像素)
LinearLayout.LayoutParams popLp = new LayoutParams(-1, height / 2);
lvPopupList.setLayoutParams(popLp);
task = new ManagementAsynTask(LoginActivity.this, lvPopupList);
task.execute();
// lvPopupList.setAdapter(new ArrayAdapter(LoginActivity.this,
// android.R.layout.simple_list_item_1,moreList));
lvPopupList.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
pwMyPopWindow.dismiss();
pwMyPopWindow = null;
userName.setText(ManagementAsynTask.user.get(arg2));
System.out.println("arg0" + arg0 + "arg1" + arg1 + "arg2"
+ arg2 + "arg3" + arg3);
Toast.makeText(LoginActivity.this, "position" + arg2, 1).show();
}
});
;
pwMyPopWindow = new PopupWindow(mypopupView, -2, -2);
pwMyPopWindow.setBackgroundDrawable(this.getResources().getDrawable(
R.drawable.bg_popupwindow));
// 加上这个属性,PopupWindow的ListView的Item才可以点击
pwMyPopWindow.setFocusable(true);
mypopupView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (pwMyPopWindow != null && pwMyPopWindow.isShowing()) {
pwMyPopWindow.dismiss();
pwMyPopWindow = null;
}
return false;
}
});
}