如何在我的地图 activity 顶部弹出一个 listView?
How can I pop a listView on top of my map activity?
我得到了基于 Google 地图 activity 的新应用程序。我将我的 onMapLongClickListener 设置为根据用户的需要添加尽可能多的新标记。但我有一个问题:我想在我的地图顶部设置一个 ListView,以允许用户在不同的标记类型之间进行选择。如何设置一个 ListView,它在我按住地图上的一个点时出现,然后在选择其中一项后消失?
这是我的应用程序代码,如果它可以帮助你提供一些解决方案!
MapsActivity.java
package com.example.mancu_000.onclickmarkerlistener;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMapLongClickListener;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, OnMapLongClickListener {
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
map = googleMap;
map.setOnMapLongClickListener(this);
map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
Toast.makeText(MapsActivity.this, "OnMarkerListener", Toast.LENGTH_SHORT).show();
return true;
}
});
LatLng home = new LatLng(44.42913, 8.84072);
map.addMarker(new MarkerOptions().position(home).title("Home, bitches!"));
map.moveCamera(CameraUpdateFactory.newLatLng(home));
CameraUpdate center = CameraUpdateFactory.newLatLng(home);
map.moveCamera(center);
CameraUpdate zoom = CameraUpdateFactory.zoomTo(17);
map.animateCamera(zoom);
}
@Override
public void onMapLongClick(LatLng location) {
// Here I'm supposed to implements thee code of the ListView on the top of the map
}
}
activity_maps.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.mancu_000.onclickmarkerlistener.MapsActivity" >
<fragment xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
class="com.google.android.gms.maps.SupportMapFragment"/>
</FrameLayout>
感谢您的支持!!
按下对话框获取标记列表,例如
@Override
public void onMapLongClick(LatLng location) {
AlertDialog.Builder builderSingle = new AlertDialog.Builder(context);
builderSingle.setIcon(R.drawable.title_icon_resource);
builderSingle.setTitle("Select One Name:-");
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>();//create adapter with your markers list
builderSingle.setNegativeButton();//to exit directly if you want
builderSingle.setAdapter(arrayAdapter,new DialogInterface.OnClickListener());//set your adapter and listener
builderSingle.show();
}
希望对您有所帮助
我得到了基于 Google 地图 activity 的新应用程序。我将我的 onMapLongClickListener 设置为根据用户的需要添加尽可能多的新标记。但我有一个问题:我想在我的地图顶部设置一个 ListView,以允许用户在不同的标记类型之间进行选择。如何设置一个 ListView,它在我按住地图上的一个点时出现,然后在选择其中一项后消失?
这是我的应用程序代码,如果它可以帮助你提供一些解决方案!
MapsActivity.java
package com.example.mancu_000.onclickmarkerlistener;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMapLongClickListener;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, OnMapLongClickListener {
private GoogleMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
map = googleMap;
map.setOnMapLongClickListener(this);
map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
Toast.makeText(MapsActivity.this, "OnMarkerListener", Toast.LENGTH_SHORT).show();
return true;
}
});
LatLng home = new LatLng(44.42913, 8.84072);
map.addMarker(new MarkerOptions().position(home).title("Home, bitches!"));
map.moveCamera(CameraUpdateFactory.newLatLng(home));
CameraUpdate center = CameraUpdateFactory.newLatLng(home);
map.moveCamera(center);
CameraUpdate zoom = CameraUpdateFactory.zoomTo(17);
map.animateCamera(zoom);
}
@Override
public void onMapLongClick(LatLng location) {
// Here I'm supposed to implements thee code of the ListView on the top of the map
}
}
activity_maps.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.mancu_000.onclickmarkerlistener.MapsActivity" >
<fragment xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
class="com.google.android.gms.maps.SupportMapFragment"/>
</FrameLayout>
感谢您的支持!!
按下对话框获取标记列表,例如
@Override
public void onMapLongClick(LatLng location) {
AlertDialog.Builder builderSingle = new AlertDialog.Builder(context);
builderSingle.setIcon(R.drawable.title_icon_resource);
builderSingle.setTitle("Select One Name:-");
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>();//create adapter with your markers list
builderSingle.setNegativeButton();//to exit directly if you want
builderSingle.setAdapter(arrayAdapter,new DialogInterface.OnClickListener());//set your adapter and listener
builderSingle.show();
}
希望对您有所帮助