Android 将值从活动传递到弹出窗口
如何将值从活动传递到弹出窗口?尽管这似乎是个愚蠢的问题。代码片段如下所示。我只需要将一个值从函数onbuttonpup()传递到弹出窗口(shape_details.xml)。提前谢谢Android 将值从活动传递到弹出窗口,android,popup,Android,Popup,如何将值从活动传递到弹出窗口?尽管这似乎是个愚蠢的问题。代码片段如下所示。我只需要将一个值从函数onbuttonpup()传递到弹出窗口(shape_details.xml)。提前谢谢 public void onButtonPopup(View target, int position) { // Make a View from our XML file LayoutInflater inflater = (LayoutInflater) this.getSystemServ
public void onButtonPopup(View target, int position) {
// Make a View from our XML file
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.shape_details, (ViewGroup) findViewById(R.id.llShapeDetails));
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
pw = new PopupWindow(layout, width - width / 4, height - height / 3, true);
pw.setAnimationStyle(R.style.PopupWindowAnimation);
pw.showAtLocation(layout, Gravity.CENTER, 0, 0);
}
要从任何活动发送/传递任何值,我们需要两个活动。第一个是“主要活动”,第二个是“PopupUpIndowActivity”。现在,我们创建“PopupUpIndowActivity” 现在,我们将从“MainActivity”发送/传递值
我需要将一个值从函数onButtonPopup()传递到弹出窗口:你想传递哪个值?比如说,要传递的字符串值,它将在弹出窗口中显示为标题文本。看到这一点,你没有明白我的意思。我以前看过这个链接。这是关于打开一个静态弹出窗口,其中的内容是固定的。最后我自己解决了这个问题。谢谢大家1:)
public class PopUpWindowActivity {
public void onButtonPopup(final View target, int position) {
//You can work here with "position"
}
}
public class MainActivity extends AppCompatActivity {
//onCreate Metod and other work here
//Here we will send/pass data to "PopUpWindowActivity"
SampleButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
PopUpWindowActivity popUpWindow = new PopUpWindowActivity();
popUpWindow.onButtonPopup(view, 1);
//I take position value is 1. You can send your own.
}
});
}