这里我在弹出窗口中使用了两个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()是我的另一种方法,我必须使用popwindow字符串CTNNO和PONO。
答案 0 :(得分:1)
在想要从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。