Google Marker onClick无法打开自定义弹出视图

时间:2018-12-20 17:39:38

标签: android maps marker

我被困了几天。无法解决我的问题:当我使用自定义标记单击标记时,它无法更新数据或显示标记信息的详细信息。

这是主要活动:

@Override
public boolean onMarkerClick(Marker marker) {

    if (marker.getTag() == null && marker.getTag() instanceof Shop) {
        shop = (Shop) marker.getTag();

    }
    mPop = new CustomPopUpWindow(MainActivity.this);
    mPop.setOnBookBatteryClick(new CustomPopUpWindow.OnBookBatteryClick() {
        @Override
        public void onClick(int shopId) {

        }
    });
    if (mPop.isShowing()) {
        mPop.updateData(shop);
    } else {
        mPop.updateData(shop);
        //mPop.showAtLocation(drawerlayout, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
    }
  return true;
}

这是自定义弹出窗口:

public void updateData(Shop shop) {
        mShop = shop;
        tv_shop_name.setText(mShop.getName());
        tv_shop_open_time.setText(mShop.getOpenTime());
        tv_address.setText(mShop.getAddress());
        tv_oil_num.setText(mShop.getBatterryAvailable());
        tv_distance.setText(mShop.getDescription());
  }
 private void init() {
    // TODO Auto-generated method stub
    LayoutInflater inflater = LayoutInflater.from(mContext);

    mPopView = inflater.inflate(R.layout.custom_popup_window, null);

    tv_shop_name = (TextView) mPopView.findViewById(R.id.tv_shop_name);
    tv_shop_open_time = (TextView) mPopView.findViewById(R.id.tv_shop_open_time);
    tv_distance = (TextView) mPopView.findViewById(R.id.tv_distance);
    tv_address = (TextView) mPopView.findViewById(R.id.tv_address);

    tv_oil_num = (TextView) mPopView.findViewById(R.id.tv_oil_num);
    btn_book_battery = mPopView.findViewById(R.id.btn_book_battery);

    iv_close = (ImageView) mPopView.findViewById(R.id.iv_close);

    btn_call_shop = mPopView.findViewById(R.id.btn_call_shop);
}

我收到此错误:

java.lang.NullPointerException
    at com.ecgo.indonesia.view.CustomPopUpWindow.updateData(CustomPopUpWindow.java:131)
    at com.ecgo.indonesia.MainActivity.onMarkerClick(MainActivity.java:482)
    at com.google.android.gms.maps.zzb.zza(Unknown Source)
    at com.google.android.gms.maps.internal.zzas.onTransact(Unknown Source)
    at android.os.Binder.transact(Binder.java:361)

0 个答案:

没有答案