Vignesh
Vignesh

Reputation: 21

How to retrieve an EditText value from a popup window?

Here i have used two EditText in pop up window and I have to pass the String PONO and CTNNO to another method in my class.So please help me how to do it.

        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() is my another method where i have to use the popwindow String CTNNO and PONO.

Upvotes: 0

Views: 1072

Answers (1)

ρяσѕρєя K
ρяσѕρєя K

Reputation: 132982

Call pono.getText() inside onClick method on which want to retrieve user input value from EditText like:

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

and also to access pono object inside onClick method either make it final pono or declare as Global in class.

Upvotes: 1

Related Questions