不能在ArrayAdapter中添加Intent到Google Maps



我有一个代码列表,它的项目是对某个东西的引用,并且有一个地址。我需要这样做,当该列表中的任何项目被点击,然后谷歌地图导航应该启动对应的地址为rowitem。顺便说一句,地址在行中是不可见的,地址是获取行信息的对象。我试过代码:-

rowview.setOnClickListener(new View.OnClickListener() 
    {
        public void onClick(View v) 
        {
            //Intent intent = new Intent(context,);
            //Toast.makeText(context, "Yeah Boy", Toast.LENGTH_SHORT).show();
            LatLng tmp = objects.get(position).location;
            String uri = "http://maps.google.com/maps?saddr=" + location.getLatitude()+","+location.getLongitude()+"&daddr="+tmp.latitude+","+tmp.longitude;  
            Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
            intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
            context.startActivity(intent);
        }
    });
    return rowview;

但它似乎不起作用。我有这个错误:-

android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity  context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?
有谁能帮我一下吗?

试试:

Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
String uri = "Your URI String ";
intent.setData(Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", 
                 "com.google.android.maps.MapsActivity");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);

构造函数Intent(int, Uri)是undefined

使用setFlag方法设置标志

Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
intent.setFlag(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);

我不知道变量"context"中的上下文是什么。

如果你的代码包含在一个活动中,而不是"context"尝试

ActivityClass.this.startActivity(意图);

最新更新