我想在mapsactivity
中显示弹出窗口,但显示错误。所以帮我从中得到
initiatePopupWindow(getWindow().getDecorView().getRootView());
弹出功能
private void initiatePopupWindow(View view) {
try {
//We need to get the instance of the LayoutInflater, use the context of this activity
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//Inflate the view from a predefined XML layout
View layout = inflater.inflate(R.layout.popup_vehicle_select,
(ViewGroup) view.findViewById(R.id.popup_element));
car = layout.findViewById(R.id.car);
bike = layout.findViewById(R.id.bike);
ChangeFont changeFont = new ChangeFont();
changeFont.overrideFonts(this, view, 1);
pw = new PopupWindow(layout, LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT, true);
// display the popup in the center
pw.setAnimationStyle(R.style.Animation);
pw.showAtLocation(layout, Gravity.CENTER, 0, 0);
} catch (Exception e) {
e.printStackTrace();
Log.e("Popup", e.getMessage());
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
显示为
“无法添加窗口 - 令牌无效无效;是你的活动 跑步吗?'
答案 0 :(得分:1)
Replace All contexts with YourActivity.this
And YOU are showing PopUp TOO early make it through PostDelayed .. you will get it
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
yourPopUp();
}
}, 1000);
答案 1 :(得分:0)
在标记上唯一标识每个标记,然后在您的位置数组中找到匹配项。
map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
LatLng latLon = marker.getPosition();
//Cycle through places array
for(Place place : places){
if (latLon.equals(place.latlng)){
//match found! Do something...
}
}
}
});