I’ve created a Main.xml with buttons. They all perform a certain action and this is all fine, but there should also be password protected buttons. So I also created a second xml (popup.xml). This should pop up if the user presses the button. In popup.xml there is just a textfield for user input and a button to submit.
At the moment I can press on the button and the popup appears, but I don’t know how to submit the user input data to the main view or just go back to the main view by pressing the button.
public class BastiLauncherActivity extends Activity implements OnClickListener {
private Button b1;
// ...
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// this b1 is a button in the main view where this pop up should appear
b1 = (Button) findViewById(R.id.b1Button);
b1.setOnClickListener(this);
// ...
}
@Override
public void onClick(View v) {
LayoutInflater inflater =
(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
PopupWindow pw = new PopupWindow(inflater.inflate(R.layout.popup, null,
false), 200, 300, true);
pw.setOutsideTouchable(true);
if (v == b1) {
// opening the popup
pw.showAtLocation(findViewById(R.id.dateiButton), Gravity.CENTER, 0, 0);
} else if (...) {
}
}
}
I see you’re using a PopupWindow – to remove it you invoke
dismiss().If you just want a pop up to capture some user input then return back to the Activity that spawned the pop up then I would suggest using a Custom Dialog. You can create whatever you like in the dialog, and add whatever buttons you need with handlers for each button. An example;