在这里我在弹出窗口中使用了两个EditText,并且我必须将String PONO和CTNNO传递给类中的另一个方法。所以请帮助我如何做。

        private String showPopup(final Activity context, Point p) {
    String a="hy";
      //Full screen popup
      int popupWidth = 1500;
      int popupHeight = 900;
      // Inflate the popup_layout.xml
      RelativeLayout viewGroup = (RelativeLayout) context.findViewById(R.id.popup);
      LayoutInflater layoutInflater = (LayoutInflater) context
              .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      View layout = layoutInflater.inflate(R.layout.popup_layout, viewGroup);

      // Creating the PopupWindow
      final PopupWindow popup = new PopupWindow(context);
      popup.setContentView(layout);
      popup.setWidth(popupWidth);
      popup.setHeight(popupHeight);
      popup.setFocusable(true);

      // Some offset to align the popup a bit to the right, and a bit down, relative to button's position.
      int OFFSET_X = 30;
      int OFFSET_Y = 30;

      // Clear the default translucent background
      popup.setBackgroundDrawable(new BitmapDrawable());
     TextView barcodeno = (TextView) layout.findViewById(R.id.textView22);
      barcodeno.setText("er31g3e3d");
         //Full screen popup
      popup.showAtLocation(layout, Gravity.CENTER,OFFSET_X,OFFSET_Y);
     EditText pono = (EditText) layout.findViewById(R.id.editText3);
      EditText ctnno = (EditText) layout.findViewById(R.id.editText4);
      PONO=pono.getText().toString();
      String CTNO=ctnno.getText().toString();
   Button btn_Assign=(Button) layout.findViewById(R.id.btn_Assign);
      btn_Assign.setOnClickListener(new View.OnClickListener() {

          @Override
          public void onClick(View v) {
              Assign();
          }
      });
      // Getting a reference to Close button, and close the popup when clicked.
      Button btn_close = (Button) layout.findViewById(R.id.close);

      btn_close.setOnClickListener(new View.OnClickListener() {

          @Override
          public void onClick(View v) {
              popup.dismiss();
          }
      });
      return a;
  }


public void Assign()是我必须使用弹出窗口字符串CTNNO和PONO的另一种方法。

最佳答案

在要从pono.getText()检索用户输入值的onClick方法内调用EditText,例如:

      @Override
      public void onClick(View v) {
         // get value from EditText here...
          PONO=pono.getText().toString();
          Assign();
      }


并且还可以在onClick方法中访问pono对象,或者将其设为final pono或在类中声明为Global。

07-25 21:35