我已经在这里附加了我的代码,我已经尝试了各种方法,但无法关闭弹出窗口,请提前帮助,谢谢
for (int i = 0; i < chitlist.size(); i++) {
if (chitid.equalsIgnoreCase(chitlist.get(i).ChitNo)) {
@SuppressWarnings("static-access")
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.monthlychitpopup, null);
popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);
popupWindow.setBackgroundDrawable(new ShapeDrawable());
popupWindow = new PopupWindow(popupView, width, height, true);
popupWindow.showAtLocation(popupView, Gravity.CENTER, 0, 0);
popupWindow.setAnimationStyle(R.style.PopupWindowAnimation);
View pView = popupWindow.getContentView();
//some code here
close = (Button) popupView.findViewById(R.id.chitpopclose);
close.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
popupWindow.dismiss();
}
});
popupWindow.setTouchInterceptor(new View.OnTouchListener() {
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
// TODO Auto-generated method stub
if (arg1.getAction() == MotionEvent.ACTION_DOWN) {
popupWindow.dismiss();
}
return true;
}
});
}
}
}
onclick和setTouchInterceptor事件都无法正常工作。
下面是我的完整弹出窗口布局,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#7F1404" >
<LinearLayout
android:id="@+id/laypop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="5dip"
android:layout_marginTop="5dip" >
<Button
android:id="@+id/chitpopclose"
android:layout_width="100dip"
android:layout_height="40dip"
android:background="@drawable/button_default_bg"
android:text="Close"
android:textColor="#5F0404" />
</LinearLayout>
<TextView
android:id="@+id/chitpopchitid"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dip"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginTop="10dip"
android:background="@drawable/rounded_edgepopup"
android:gravity="center"
android:text="ChitId"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="17dip"
android:textStyle="bold" />
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/chitpopchitid"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:background="@drawable/rounded_edgepopup"
android:orientation="vertical"
android:padding="10dip" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="110dip"
android:layout_height="wrap_content"
android:text="Month Amt"
android:textSize="16dip" />
<TextView
android:id="@+id/chitpopmnamt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Month Amt"
android:textSize="16dip" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="110dip"
android:layout_height="wrap_content"
android:text="Installment"
android:textSize="16dip" />
<TextView
android:id="@+id/chitpopinstallment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Installment"
android:textSize="16dip" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="110dip"
android:layout_height="wrap_content"
android:text="Rec.Amount"
android:textSize="16dip" />
<TextView
android:id="@+id/chitpoptotamt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Re.Amount"
android:textSize="16dip" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="110dip"
android:layout_height="wrap_content"
android:text="Chit Date"
android:textSize="16dip" />
<TextView
android:id="@+id/chitpopchitdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Chit Date"
android:textSize="16dip" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/laypop"
android:layout_below="@+id/linearLayout1"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginTop="5dp"
android:background="@drawable/rounded_edgepopup"
android:orientation="vertical"
android:padding="5dip" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/main_color_gray_dk"
android:gravity="center_vertical"
android:padding="10dp" >
<TextView
android:layout_width="0.0dip"
android:layout_height="wrap_content"
android:text="S.No"
android:layout_weight="0.2"
android:textColor="@color/white"
android:textSize="13dp" />
<View
android:layout_width="0.75dip"
android:layout_height="fill_parent"
android:layout_marginRight="10dp"
android:background="@color/gray_light" />
<TextView
android:layout_width="0.0dip"
android:layout_height="wrap_content"
android:text="Date"
android:layout_weight="0.4"
android:textColor="@color/white"
android:textSize="13dp" />
<View
android:layout_width="0.75dip"
android:layout_height="fill_parent"
android:layout_marginRight="0dp"
android:background="@color/gray_light" />
<TextView
android:layout_width="0.0dip"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_weight="0.4"
android:text="Amount(Rs.)"
android:textColor="@color/white"
android:textSize="13dp" />
</LinearLayout>
<GridView
android:id="@+id/popchitgriddetail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnWidth="100dp"
android:gravity="center"
android:numColumns="1" >
</GridView>
</LinearLayout>
</RelativeLayout>
答案 0 :(得分:0)
删除第二次初始化弹出窗口的最后一行。
popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);
popupWindow.setBackgroundDrawable(new ShapeDrawable());
popupWindow = new PopupWindow(popupView, width, height, true);