Android ListView项目选定事件

时间:2014-11-19 07:12:27

标签: android listview map infowindow

我正在尝试根据从listview中选择的项目弹出标记上的信息窗口。所以基本上当选择listview项时,它将执行createCallOutView():

listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View item,
                int position, long id) {

            float x = Float.parseFloat(_eventlist.get(position).getEventX());
            float y = Float.parseFloat(_eventlist.get(position).getEventY());

            ENeighbourhoodActivity.callout.hide();
            int[] graphicIDs = ENeighbourhoodActivity.graphicsLayer.getGraphicIDs(x, y, 25);
            if (graphicIDs != null && graphicIDs.length > 0) {
                Graphic gr = ENeighbourhoodActivity.graphicsLayer.getGraphic(graphicIDs[0]);
                Point location = (Point) gr.getGeometry();
                ENeighbourhoodActivity.callout.setOffset(0, -10);
                ENeighbourhoodActivity.callout.show(location, EventInfoWindow.createCalloutView(
                        gr, context, userID));
            } 
            getActivity().finish();

        }
    });

在我的createCallOutView()中,它基本上只显示事件的详细信息。但是,使用这些代码,当选择列表视图项时,屏幕只是冻结,一段时间后它只显示应用程序没有响应消息并关闭活动。

有什么想法吗?根本没有错误消息。提前谢谢。

1 个答案:

答案 0 :(得分:0)

可能是您的代码在图形部分需要更多时间。 Pt在另一个线程中,以便主线程不会停止。

listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View item,
            int position, long id) {
        new Thread(new Runnable() {
        @Override
        public void run() {
          float x = Float.parseFloat(_eventlist.get(position).getEventX());
          float y = Float.parseFloat(_eventlist.get(position).getEventY());

          ENeighbourhoodActivity.callout.hide();
          int[] graphicIDs = ENeighbourhoodActivity.graphicsLayer.getGraphicIDs(x, y, 25);
         if (graphicIDs != null && graphicIDs.length > 0) {
            Graphic gr = ENeighbourhoodActivity.graphicsLayer.getGraphic(graphicIDs[0]);
            Point location = (Point) gr.getGeometry();
            ENeighbourhoodActivity.callout.setOffset(0, -10);
            ENeighbourhoodActivity.callout.show(location, EventInfoWindow.createCalloutView(
                    gr, context, userID));

         } 
         getActivity().finish();
        }
        }).start();


    }
});

当您想要更新UI时,别忘了使用 runOnUiThread