2011-08-14 16 views
0

ポップアップを表示しないようにする問題があります。私が見えるようにするために押すと、表示されますが、キャンセルボタン(Canceボタンはポップアップ上にあります)を押すと、目に見えなくなりません。ポップアップは表示されませんが、コードを通過して何も起こりません。

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(); 
      } 

     } 
    }); 

これは誰もが私を助けることができる私が間違って作る何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> 

のですか?

答えて

2
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(); 
     } 

    } 
}); 

あなたが新しいViewを作成しているinflateメソッドを呼び出すたびに、したがって、リスナーを設定するキャンセルボタンは、ポップアップの内側にあるキャンセルボタンとは異なります。上記のように、同じViewは、ポップアップを初期化し、クリックリスナーを設定するために使用されます。

+0

@Christianありがとうございました! – Damir

関連する問題