点击打开一个最初隐藏的列表视图
On tap open a listview that is hidden at first
我有一张地图,在 android studio 上使用 google maps api2,当我点击任何地方时,我想打开一个列表视图,其中会有单选按钮和其他类型的东西。我不知道该怎么做,如何使用意图,如何使用听众,任何人都可以帮助我吗?这是我到目前为止得到的代码:
public class MainActivity extends FragmentActivity implements OnMapReadyCallback,LocationListener {
private MapView mapV;
private GoogleMap map;
private GoogleMapOptions options;
private CameraUpdate camUp;
private double lat,lon;
private LatLng koordinate;
private String provider;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
map = fm.getMap();
map.setMyLocationEnabled(true);
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
provider = locationManager.getBestProvider(criteria, true);
Location location = locationManager.getLastKnownLocation(provider);
koordinate = new LatLng(location.getLatitude(),location.getLongitude());
if(location!=null){
onLocationChanged(location);
}
locationManager.requestLocationUpdates(provider, 20000, 0, this);
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(koordinate, 10);
map.animateCamera(cameraUpdate);
}
public void openList(View view)
{
Intent intent = new Intent(intent.ACTION_VIEW ,);
ListView list = (ListView) findViewById(R.id.idList);
}
XML 文件:
<RelativeLayout 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=".MainActivity" >
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
<ExpandableListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/idList"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:onClick="openList"/>
Intent class 通常与按钮相关联。
单击按钮时,Intent class 可用于简单地 wake/start 另一个 activity 或者它可以将一些数据 (String/int/etc) 传递给 activity,如果需要,它还可以取回一些数据。
要简单地唤醒另一个 activity,您需要:
Intent i = new Intent (*activity_action_name*);
startActivity(i);
对于听众来说,onClick比较多的时候使用比较好。因为这是减少数据冗余的好方法。如果你只有一个 onClick。没有必要使用 OnClickListener。
示例:如果您有两个按钮。您可以执行以下操作。
//in onCreate declare some buttons
Button bt1 = (Button) findViewById(R.id.*button1_id*);
bt1.setOnClickListener(new clsOnClickListener());
Button bt2 = (Button) findViewById(R.id.*button2_id*);
bt2.setOnClickListener(new clsOnClickListener());
//You can create a class that implements OnClickListener
private class clsOnClickListener implements View.OnClickListener{
public void onClick(View v){
if (v.getId()==R.id.button1_id{
//do what you want
}
else if (v.getId()==R.id.button2_id){
//do something else
}
}
}
为了在地图上做到这一点,您必须创建 InfoWindow with custom layout that will contain the widgets that you mentioned. Here is 示例教程。
我有一张地图,在 android studio 上使用 google maps api2,当我点击任何地方时,我想打开一个列表视图,其中会有单选按钮和其他类型的东西。我不知道该怎么做,如何使用意图,如何使用听众,任何人都可以帮助我吗?这是我到目前为止得到的代码:
public class MainActivity extends FragmentActivity implements OnMapReadyCallback,LocationListener {
private MapView mapV;
private GoogleMap map;
private GoogleMapOptions options;
private CameraUpdate camUp;
private double lat,lon;
private LatLng koordinate;
private String provider;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
map = fm.getMap();
map.setMyLocationEnabled(true);
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
provider = locationManager.getBestProvider(criteria, true);
Location location = locationManager.getLastKnownLocation(provider);
koordinate = new LatLng(location.getLatitude(),location.getLongitude());
if(location!=null){
onLocationChanged(location);
}
locationManager.requestLocationUpdates(provider, 20000, 0, this);
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(koordinate, 10);
map.animateCamera(cameraUpdate);
}
public void openList(View view)
{
Intent intent = new Intent(intent.ACTION_VIEW ,);
ListView list = (ListView) findViewById(R.id.idList);
}
XML 文件:
<RelativeLayout 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=".MainActivity" >
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
<ExpandableListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/idList"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:onClick="openList"/>
Intent class 通常与按钮相关联。 单击按钮时,Intent class 可用于简单地 wake/start 另一个 activity 或者它可以将一些数据 (String/int/etc) 传递给 activity,如果需要,它还可以取回一些数据。
要简单地唤醒另一个 activity,您需要:
Intent i = new Intent (*activity_action_name*);
startActivity(i);
对于听众来说,onClick比较多的时候使用比较好。因为这是减少数据冗余的好方法。如果你只有一个 onClick。没有必要使用 OnClickListener。
示例:如果您有两个按钮。您可以执行以下操作。
//in onCreate declare some buttons
Button bt1 = (Button) findViewById(R.id.*button1_id*);
bt1.setOnClickListener(new clsOnClickListener());
Button bt2 = (Button) findViewById(R.id.*button2_id*);
bt2.setOnClickListener(new clsOnClickListener());
//You can create a class that implements OnClickListener
private class clsOnClickListener implements View.OnClickListener{
public void onClick(View v){
if (v.getId()==R.id.button1_id{
//do what you want
}
else if (v.getId()==R.id.button2_id){
//do something else
}
}
}
为了在地图上做到这一点,您必须创建 InfoWindow with custom layout that will contain the widgets that you mentioned. Here is 示例教程。