Reputation: 2443
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:
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
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
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