gpt4 book ai didi

java - 如何从弹出窗口中检索 EditText 值?

转载 作者:行者123 更新时间:2023-12-01 10:30:23 24 4
gpt4 key购买 nike

这里我在弹出窗口中使用了两个 EditText,我必须将字符串 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。

最佳答案

在想要从 EditText 检索用户输入值的 onClick 方法中调用 pono.getText(),如下所示:

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

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

关于java - 如何从弹出窗口中检索 EditText 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35123185/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com