Banana
Banana

Reputation: 2443

Custom popup activity in android instead of dialogue

I am making an app that uses maps api, and I want to create a custom popup activity when the user creates a marker (not the generic yes/no dialogue). What I want to do is:

  1. when a user longclicks on map it opens a new activity instead of dialogue
  2. this activity displays lat and lang, has a field to enter text, and yes/no buttons
  3. if a user clicks yes the marker is pinned if no it is not
  4. when a user clicks on the created marker it displays lat,lng and the entered text

My current code:

    //Add marker on long click
    mMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {

    @Override
    public void onMapLongClick(LatLng arg0) {

        Intent intent = new Intent(getActivity(), CreateRestautantActivity.class);
        startActivity(intent);

        marker = mMap.addMarker(new MarkerOptions()
                .icon(BitmapDescriptorFactory.fromResource(R.drawable.custom_marker))
                .position(
                        new LatLng(arg0.latitude,
                                arg0.longitude))
                .visible(true));

      }
    });

Any help is appreciated :)

Upvotes: 0

Views: 492

Answers (2)

nasch
nasch

Reputation: 5498

You should use a DialogFragment. This allows you to customize the appearance and functionality of a dialog.

Android blog post on how to use them: http://android-developers.blogspot.com/2012/05/using-dialogfragments.html

Reference: https://developer.android.com/reference/android/app/DialogFragment.html

Several other tutorials/examples: https://www.google.com/search?q=dialogfragment

Upvotes: 1

Goltsev Eugene
Goltsev Eugene

Reputation: 3627

Ok, maybe I didn't got all the details, but in such case I'd do the following:

1. Use OnMapLongClickListener. Then in onMapLongClick() you can do whatever you want. You have LatLng object with latitude and longitude - you can put them in a Bundle or pass them in other way to new Activity.
You can refer this post for example.
Create a Marker and store it as a field in your Activity.

2. It's easy, I suppose, to make xml for new Activity and use it at setContentView(). Take your arguments passed in previous step and put them in lat and lng fields. Put OnClickListener on your buttons.

3. You can start your new Activity with StartActivityForResult method and handle results from your new Activity on return. There is also a lot of information about that on stackoverflow. For example this.
Then, in onActivityResult() you can make some actions to your Marker (remove it, for example).

4. Use OnMarkerClickListener - and in onMarkerClick(Marker marker) from that Marker you can call getPosition() - and take lat and lng from it.

If you need more details, let me know ;)

Upvotes: 1

Related Questions