选择项目时充气气球

发布于 2024-11-09 12:30:46 字数 301 浏览 0 评论 0原文

我有一个地图活动,其中有许多地图图钉,当我单击图钉时,会打开一个自定义气球,显示有关该图钉的一些信息。另外,我有一个搜索栏,如果您输入旋钮的名称,信息就会出现在那里,但我希望它转到搜索到的引脚。 示例: 在地图上你有不同的蔬菜图钉,当你搜索胡萝卜时,搜索列表会显示元素胡萝卜,当你点击它时,胡萝卜图钉的气球会出现膨胀。所以,我的问题是:是否有某种OnTap() void方法?我知道,OnTap(int index) 返回一个布尔值。

I have a map activity that has many pins of map, and when I click a pin, a custom balloon opens, showing some information about that pin. Also, I have a search bar, where if you type the name of a knob, the info appears there, but I want it to go to that searched pin.
Example: on the map you have different vegetables pins, and when you search carrot, the search list will show the element carrot, and when you click on it, the balloon for the carrot pin will inflate. So, my question is : is there some sort of OnTap() void method ? I know, that OnTap(int index) returns a boolean.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不再让梦枯萎 2024-11-16 12:30:46

创建您自己的逐项覆盖,并重写 onTap 方法,并在您的主类中,创建逐项覆盖的实例,并调用overlay.onTap(point)

示例代码:

public class MyItemizedOverlay<Item> extends ItemizedOverlay<OverlayItem> {
    private ArrayList<OverlayItem> m_overlays;
    private MapView mapView;
    final MapController mc;

    public MyItemizedOverlay(Drawable defaultMarker, MapView mapView) {
        super(boundCenterBottom(defaultMarker), mapView);
        m_overlays = new ArrayList<OverlayItem>();
        mc = mapView.getController();
        populate();
    }

    public void addOverlay(OverlayItem overlay) {
        m_overlays.add(overlay);
        setLastFocusedIndex(-1);
        populate();
    }

    public ArrayList<OverlayItem> getOverlays() {
        return m_overlays;
    }

    public final boolean onTap(int index) {
        GeoPoint point;
        point = createItem(index).getPoint();
        mc.animateTo(point);    
        return true;
    }

    ...
}

在主类中

public class Main extends MapActivity {
    private MapView mapView;
private List<Overlay> mapOverlays;
    private MyItemizedOverlay overlay;
private Drawable pin;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        doAction();
    }

    private void doAction() {
    mapView = (MapView)findViewById(R.id.map_view);
        pin = res.getDrawable(R.drawable.pin);

        overlay = new MyItemizedOverlay(pin, mapView);

        GeoPoint point = new GeoPoint((int)(7*1E6),(int)(42*1E6));
        overlayItem = new OverlayItem(point, "title", "text");

    overlay.addOverlay(overlayItem);

        mapOverlays = mapView.getOverlays();
    mapOverlays.add(overlay);

        //we tap the point here
        overlay.onTap(0);
    }
}

create your own itemized overlay, and override the onTap method, and in your main class, make an instance of the itemized overlay, and call overlay.onTap(point)

Sample code:

public class MyItemizedOverlay<Item> extends ItemizedOverlay<OverlayItem> {
    private ArrayList<OverlayItem> m_overlays;
    private MapView mapView;
    final MapController mc;

    public MyItemizedOverlay(Drawable defaultMarker, MapView mapView) {
        super(boundCenterBottom(defaultMarker), mapView);
        m_overlays = new ArrayList<OverlayItem>();
        mc = mapView.getController();
        populate();
    }

    public void addOverlay(OverlayItem overlay) {
        m_overlays.add(overlay);
        setLastFocusedIndex(-1);
        populate();
    }

    public ArrayList<OverlayItem> getOverlays() {
        return m_overlays;
    }

    public final boolean onTap(int index) {
        GeoPoint point;
        point = createItem(index).getPoint();
        mc.animateTo(point);    
        return true;
    }

    ...
}

In the main class

public class Main extends MapActivity {
    private MapView mapView;
private List<Overlay> mapOverlays;
    private MyItemizedOverlay overlay;
private Drawable pin;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        doAction();
    }

    private void doAction() {
    mapView = (MapView)findViewById(R.id.map_view);
        pin = res.getDrawable(R.drawable.pin);

        overlay = new MyItemizedOverlay(pin, mapView);

        GeoPoint point = new GeoPoint((int)(7*1E6),(int)(42*1E6));
        overlayItem = new OverlayItem(point, "title", "text");

    overlay.addOverlay(overlayItem);

        mapOverlays = mapView.getOverlays();
    mapOverlays.add(overlay);

        //we tap the point here
        overlay.onTap(0);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文