4

メニューボタンのクリックからポップアップを呼び出す次の関数があります。ポップアップを閉じるためのOKボタンがあります。ただし、onclickボタンを押しても機能は開始されません。また、戻るボタンが押されたときにポップアップを閉じる必要があります。

    LayoutInflater inflater = (LayoutInflater) MainActivity.this
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    final PopupWindow pw = new PopupWindow(inflater.inflate(R.layout.about_popup, null, false),400,440, true);

    pw.showAtLocation(lv, Gravity.CENTER, 0, 0);
    View popupView=inflater.inflate(R.layout.about_popup, null, false);
    Button close = (Button) popupView.findViewById(R.id.okbutton);
    close.setOnClickListener(new OnClickListener() {

      public void onClick(View popupView) {
        pw.dismiss();
      }
    });

ありがとう

4

3 に答える 3

10

現在、 View の別のインスタンスを渡して、違いのインスタンスでPopupWindowButton を見つけようとしていますが、PopupWindow で渡した同じインスタンスを使用して button を見つけます。コードを次のように変更します。

  LayoutInflater inflater = (LayoutInflater) MainActivity.this
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  View popupView = layoutInflater.inflate(R.layout.about_popup, null, false);
  final PopupWindow pw = new PopupWindow(popupView,400,440, true);

  pw.showAtLocation(lv, Gravity.CENTER, 0, 0);
    Button close = (Button) popupView.findViewById(R.id.okbutton);
    close.setOnClickListener(new OnClickListener() {

      public void onClick(View popupView) {
        pw.dismiss();
      }
    });

2番目の方法は、PopupWindowインスタンスを使用して、ボタンの膨張レイアウト内の現在のウィンドウのボタンを次のように見つけることです。

Button close = (Button) pw.findViewById(R.id.okbutton);
close.setOnClickListener(new OnClickListener() {

          public void onClick(View popupView) {
            pw.dismiss();
          }
        });
于 2013-03-02T05:57:10.853 に答える
1
CustomDialogClass cdd = new CustomDialogClass(this,
                "Internet Connection Error",
                "Sorry, no internet connection.Feeds cannot be refreshed",
                "Alert");
        cdd.show();

public class CustomDialogClass extends Dialog implements
    android.view.View.OnClickListener {
String txtTitle, txtText, txtType;
Button btn;
TextView alertText;
ImageView imgVw;

public CustomDialogClass(Context context, String title, String text,
        String type) {
    super(context);
    txtTitle = title;
    txtText = text;

}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.alert_layout);
    imgVw = (ImageView) findViewById(R.id.iconImgview);

    alertText = (TextView) findViewById(R.id.AlertText);
    alertText.setText(txtText);

    btn = (Button) findViewById(R.id.dismis_dialog);
    btn.setOnClickListener(this);
}

@Override
public void onClick(View v) {
    dismiss();
}
于 2013-03-02T06:01:39.697 に答える
0

これを変える

  View popupView=inflater.inflate(R.layout.about_popup, null, false);
    Button close = (Button) popupView.findViewById(R.id.okbutton);

 Button close = (Button) pw.findViewById(R.id.okbutton);
于 2013-03-02T05:57:00.513 に答える