Android地图2版点击弹出 [英] Android maps v2 click on popup

查看:119
本文介绍了Android地图2版点击弹出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在那里发动意图另一个活动点击谷歌地图V2弹出的方法?

is there a way to launch an intent to another activity clicking in a google maps v2 popup?

这是我的code:

@Override
public View getInfoContents(Marker marker) 
{
    View popup=inflater.inflate(R.layout.popup, null);

    final TextView tvtitulo=(TextView)popup.findViewById(R.id.tvTitulo);
    TextView tvDatos=(TextView)popup.findViewById(R.id.tvDatos);
    TextView tvCat=(TextView)popup.findViewById(R.id.tvCategoria);

    tvtitulo.setText(marker.getTitle());

    StringTokenizer tokens = new StringTokenizer(marker.getSnippet(), "?");
    final String first = tokens.nextToken();// this will contain "Fruit"
    String second = tokens.nextToken();// this will contain " they taste good"

    tvDatos.setText(first);
    tvCat.setText(second);

    ImageView imagen = (ImageView)popup.findViewById(R.id.menuImgView);

    if(marker.getTitle().substring(0,3).equalsIgnoreCase("Bar"))
        imagen.setBackgroundResource(R.drawable.bar);

    else if(marker.getTitle().substring(0,3).equalsIgnoreCase("Res"))
        imagen.setBackgroundResource(R.drawable.rest);
    else
        imagen.setVisibility(4);

    return(popup);
}

我想这样的补充一点,就是方法内:

I would like to add something like this inside that method:

 popup.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent(getApplicationContext(), InfoLocal.class);
            startActivity(intent);
            finish();
        }
    });

THX你的答案和对不起我的英语水平。

Thx for your answers and sorry for my english.

推荐答案

是的,有,下面就来看看我是怎么做到的,你在code意见,了解正在发生的事情:

Yes there is, here take a look at how I did it,you have comments in the code to understand what is going on:

// Setting a custom info window adapter for the google map
        map.setInfoWindowAdapter(new InfoWindowAdapter() {

            // Use default InfoWindow frame
            @Override
            public View getInfoWindow(Marker args) {
                return null;
            }

            // Defines the contents of the InfoWindow
            @Override
            public View getInfoContents(Marker args) {

                // Getting view from the layout file info_window_layout
                View v = getLayoutInflater().inflate(R.layout.info_window_layout, null);

                // Getting the position from the marker
                clickMarkerLatLng = args.getPosition();

                TextView title = (TextView) v.findViewById(R.id.tvTitle);
                title.setText(args.getTitle());

                map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {          
                    public void onInfoWindowClick(Marker marker) 
                    {
                        if (SGTasksListAppObj.getInstance().currentUserLocation!=null)
                        {   
                            if (String.valueOf(SGTasksListAppObj.getInstance().currentUserLocation.getLatitude()).substring(0, 8).contains(String.valueOf(clickMarkerLatLng.latitude).substring(0, 8)) &&
                                    String.valueOf(SGTasksListAppObj.getInstance().currentUserLocation.getLongitude()).substring(0, 8).contains(String.valueOf(clickMarkerLatLng.longitude).substring(0, 8)))
                            {
                                Toast.makeText(getApplicationContext(), "This your current location, navigation is not needed.",  Toast.LENGTH_SHORT).show();
                            }
                            else
                            {
                                FlurryAgent.onEvent("Start navigation window was clicked from daily map");
                                tasksRepository = SGTasksListAppObj.getInstance().tasksRepository.getTasksRepository();
                                for (Task tmptask : tasksRepository)
                                {
                                    String tempTaskLat = String.valueOf(tmptask.getLatitude());
                                    String tempTaskLng = String.valueOf(tmptask.getLongtitude());

                                    Log.d(TAG, String.valueOf(tmptask.getLatitude())+","+String.valueOf(clickMarkerLatLng.latitude).substring(0, 8));

                                    if (tempTaskLat.contains(String.valueOf(clickMarkerLatLng.latitude).substring(0, 8)) && tempTaskLng.contains(String.valueOf(clickMarkerLatLng.longitude).substring(0, 8)))
                                    {  
                                        task = tmptask;
                                        break;
                                    }
                                }
                                Intent intent = new Intent(getApplicationContext() ,RoadDirectionsActivity.class);
                                intent.putExtra(TasksListActivity.KEY_ID, task.getId());
                                startActivity(intent);

                            }
                        }
                        else
                        {
                            Toast.makeText(getApplicationContext(), "Your current location could not be found,\nNavigation is not possible.",  Toast.LENGTH_SHORT).show();
                        }
                    }
                });

                // Returning the view containing InfoWindow contents
                return v;

            }
        });  

这篇关于Android地图2版点击弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆