Как перенести результат из AlertDialog в сниппет Custom Marker? - PullRequest
0 голосов
/ 05 августа 2020

Я написал код, но после того, как я нажму «ОК», мое приложение выйдет из строя. Мне нужна информация из AlertDialog, чтобы она была в InfoWindow в GoogleMap. Много чего перепробовал, но ответа не нашел.

У меня есть еще 3 кнопки (они меняют значок маркера)

        fab2.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Toast.makeText(PersonMapActivity.this, "Marker had been chosen", 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);
        }
    });
}
...