I'm working on a project for college that will let a user place a point on a map and then set the title and description for the overlay object. The problem is, the second EditText
box overwrites the first one. Here is my code for the dialog box.
//Make new Dialog
AlertDialog.Builder dialog = new AlertDialog.Builder(mapView.getContext());
dialog.setTitle("Set Target Title & Description");
dialog.setMessage("Title: ");
final EditText titleBox = new EditText(mapView.getContext());
dialog.setView(titleBox);
dialog.setMessage("Description: ");
final EditText descriptionBox = new EditText(mapView.getContext());
dialog.setView(descriptionBox);
Any help would be appreciated!! Thanks!
Code for create a popup with two EditText using Xamarin
You can build your layout that contains two EditText, inflate it with a
LayoutInflater
and use that as the View of yourAlertDialog
.you can add your EditText programmatically too like this:
A Dialog only contains one root View, that's why
setView()
overwrites the first EditText. The solution is simple put everything in one ViewGroup, for instance a LinearLayout:(This is a basic example, but it should get you started.)
You should take note of the nomenclature difference between a
set
andadd
method.setView()
only holds one View, the same is similar forsetMessage()
. In fact this should be true for everyset
method, what you're thinking of areadd
commands.add
methods are cumulative, they build a list of everything you push in whileset
methods are singular, they replace the existing data.