S
S
sarascript2020-08-05 09:44:11
Java
sarascript, 2020-08-05 09:44:11

How to add what the user entered into AlertDialog in InfoWindow in GoogleMap?

After clicking the "OK" button in the AlertDialog window, my application crashes. I have three different buttons for markers (the only difference is that the user can select an icon) and on one I wrote the following code:

fab2.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Toast.makeText(PersonMapActivity.this, "Маркер выбран", Toast.LENGTH_SHORT).show();
                GeoFire geofire = new GeoFire(PersonDatabaseRef);
                geofire.setLocation(personId, new GeoLocation(lastLocation.getLatitude(), lastLocation.getLongitude()));


                PersonPostion = new LatLng(lastLocation.getLatitude(),lastLocation.getLongitude());
                BitmapDescriptor icon = BitmapDescriptorFactory.fromResource(R.drawable.oxygen);
                LayoutInflater li = LayoutInflater.from(context);
                View promptsView = li.inflate(R.layout.android_user_input_dialog, null);

                final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                        context);

                // set prompts.xml to alertdialog builder
                alertDialogBuilder.setView(promptsView);


                final EditText userInput = (EditText) promptsView
                        .findViewById(R.id.editTextDialogUserInput);

                // set dialog message
                alertDialogBuilder
                        .setCancelable(false)
                        .setPositiveButton("OK",
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog,int id) {
                                        // get user input and set it to result
                                        // edit text
                                        result.setText(userInput.getText());
                                    }
                                })
                        .setNegativeButton("Cancel",
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog,int id) {
                                        dialog.cancel();
                                    }
                                });

                // create alert dialog
                AlertDialog alertDialog = alertDialogBuilder.create();
                alertDialog.show();
                MarkerOptions markerOptions = new MarkerOptions().position(PersonPostion)
                        .snippet(String.valueOf(result)).icon(icon)
                        .title("ss");


                mMap.addMarker(markerOptions);
            }
        });
    }


I have two screens - volunteers and users. The essence of the program is that the user leaves a label asking for help (selecting the desired marker) and has the opportunity to enter the essence of the problem.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question