Popup doesn't become unvisible but it pass through code and nothing happens
I have problem to make popup unvisible. When I press to show it becomes visible but when I press Cancel button ( Cance button is on popup) it doesn't become unvisible but it pass normal through code and nothing.
final PopupWindow pw = new PopupWindow(inflater.inflate(R.layout.popup,
null, false), 300, 300, true);
View layout = inflater.inflate(R.layout.popup,
(ViewGroup) findViewById(R.id.llPopup));
Button btnOK = (Button) layout.findViewById(R.id.btnOK);
Button btnCancel = (Button) layout.findViewById(R.id.btnCancel);
btnCancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
开发者_如何学编程 // TODO Auto-generated method stub
if (pw != null) {
pw.dismiss();
}
}
});
this is popup.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:padding="10dip"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#AAAAAAAA"
android:id="@+id/llPopup"
>
<LinearLayout
android:orientation="horizontal"
android:padding="10dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/txtSearchBy"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search By:"
/>
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:orientation="vertical">
<RadioButton
android:id="@+id/rbPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Time" />
<RadioButton
android:id="@+id/rbDuration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Price" />
<RadioButton
android:id="@+id/rbLongitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Longitude" />
</RadioGroup>
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
<Button
android:id="@+id/btnCancel"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:text="Cancel"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
/>
<Button
android:id="@+id/btnOK"
android:layout_width="100sp"
android:layout_height="wrap_content"
android:text="OK"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
</LinearLayout>
What I make wrong can anybody help me ?
View layout = inflater.inflate(R.layout.popup,
(ViewGroup) findViewById(R.id.llPopup));
final PopupWindow pw = new PopupWindow(layout, 300, 300, true);
Button btnOK = (Button) layout.findViewById(R.id.btnOK);
Button btnCancel = (Button) layout.findViewById(R.id.btnCancel);
btnCancel.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
if (pw != null) {
pw.dismiss();
}
}
});
Each time you call inflate
method you are creating a new View
; thus, the cancel button that you set the listener to is different from the one that is inside the popup. As you can see above, the same View
is used to both: initialize the popup and set the click listener.
精彩评论