问题描述
您好我实现了一个谷歌地图投影点,因此当我点击一个点它开辟了表示有关它的一些信息的气球。我已经使用这个的资源,这使得它更容易比较(感谢Paul萨西克指导)。当我在每个气球应该开辟一个新的活动点击我要的是,我试图实现在其方法的onTap但问题是,我在从一类的FrameLayout扩展一个类不能startActivity。因此,这里是我的code:
公共类CouponMapView扩展MapActivity {
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
ItemizedOverlay itemizedoverlay =新ItemizedOverlay(绘制,图形页面);
//所有mapoverlay code到这里...........
//这部分工作正常。 }
}
// ----类ItemizedOverlay在即时通讯调用startActivity ----- 的
公共类ItemizedOverlay扩展BalloonItemizedOverlay< OverlayItem> {
私人的ArrayList< OverlayItem>覆盖=新的ArrayList< OverlayItem>();
私人上下文的背景下;
私人诠释身份证; 公共ItemizedOverlay(可绘制defaultMarker,MapView类MapView类){
超(boundCenter(defaultMarker),图形页面);
上下文= mapView.getContext();
} 公共无效addOverlay(OverlayItem叠加){
overlays.add(覆盖);
填充();
} @覆盖
保护OverlayItem createItem中(int i)以{
返回overlays.get(ⅰ);
} @覆盖
公众诠释大小(){
返回overlays.size();
} @覆盖
保护布尔onBalloonTap(INT指数){
// ---我不能在这里调用startActivity因为这个类是不是从它的活动扩展//从从的FrameLayout扩展一个类,如果你向下滚动,你会发现inhereted。
子活动分=新的子活动();
sub.startCustomActivity();
返回true;
}
}
// - 要开始新的活动,并呼吁startActivity方法,我要创建一个新的类,它的活动扩展... 的
公共类子活动延伸活动{
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
}
公共无效startCustomActivity(){
意图详情=新意图(getBaseContext(),Tab.class);
Details.putExtra(ID,1327);
startActivity(详细信息);
}}
输出:
着粘贴图像直接的联系是这个
上面的图片就是类似于我收到所以,当我点击重叠这应该启动一个新的活动的意图,我想展示一些细节。
但是,当我点击它,我得到这些错误。我不知道我是否做了正确的方式。我打电话的子活动类单击图像时。
02-21 19:21:44.769:ERROR / AndroidRuntime(462):致命异常:主要
02-21 19:21:44.769:ERROR / AndroidRuntime(462):显示java.lang.NullPointerException
02-21 19:21:44.769:ERROR / AndroidRuntime(462):在android.content.ComponentName<&初始化GT;(ComponentName.java:75)
02-21 19:21:44.769:ERROR / AndroidRuntime(462):在android.content.Intent<&初始化GT;(Intent.java:2678)
02-21 19:21:44.769:ERROR / AndroidRuntime(462):在com.vouchacha.mvc.mapview.SubActivity.startCustomActivity(SubActivity.java:17)
02-21 19:21:44.769:ERROR / AndroidRuntime(462):在com.vouchacha.mvc.mapview.ItemizedOverlay.onBalloonTap(ItemizedOverlay.java:52)
02-21 19:21:44.769:ERROR / AndroidRuntime(462):在com.vouchacha.mvc.mapview.BalloonItemizedOverlay $ 1.onTouch(BalloonItemizedOverlay.java:177)
02-21 19:21:44.769:ERROR / AndroidRuntime(462):在android.view.View.dispatchTouchEvent(View.java:3762)
02-21 19:21:44.769:ERROR / AndroidRuntime(462):在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:897)
02-21 19:21:44.769:ERROR / AndroidRuntime(462):在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
02-21 19:21:44.769:ERROR / AndroidRuntime(462):在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
02-21 19:21:44.769:ERROR / AndroidRuntime(462):在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
02-21 19:21:44.769:ERROR / AndroidRuntime(462):在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
02-21 19:21:44.769:ERROR / AndroidRuntime(462):在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
02-21 19:21:44.769:ERROR / AndroidRuntime(462):在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
02-21 19:21:44.769:ERROR / AndroidRuntime(462):在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
02-21 19:21:44.769:ERROR / AndroidRuntime(462):在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
02-21 19:21:44.769:ERROR / AndroidRuntime(462):在com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1671)
很简单的解决这个:
替换此:
子活动分=新的子活动();
sub.startCustomActivity();
本:
意向详细=新意图(背景下,Tab.class);
Details.putExtra(ID,1327);
context.startActivity(详细信息);
使用背景
您从图形页面
您在覆盖类传入开始您的活动得到了变数。
Hi I have implemented a google map with projection points so when i click a point it opens up a balloon showing some information relating to it. I have used this github resource which makes it quite easier (thanks to Paul Sasik for guidance). What i want is when i click on each baloon it should open up a new Activity, I have tried implementing that in its onTap method but the problem is that i cant startActivity in a class that is extended from a framelayout class. So here is my code :
public class CouponMapView extends MapActivity{
@Override
public void onCreate(Bundle savedInstanceState) {
ItemizedOverlay itemizedoverlay = new ItemizedOverlay(drawable, mapView);
//all the mapoverlay code goes here...........
//this part works fine.
}
}
//----Class ItemizedOverlay in which im calling startActivity-----
public class ItemizedOverlay extends BalloonItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> overlays = new ArrayList<OverlayItem>();
private Context context;
private int id;
public ItemizedOverlay(Drawable defaultMarker, MapView mapView) {
super(boundCenter(defaultMarker), mapView);
context = mapView.getContext();
}
public void addOverlay(OverlayItem overlay) {
overlays.add(overlay);
populate();
}
@Override
protected OverlayItem createItem(int i) {
return overlays.get(i);
}
@Override
public int size() {
return overlays.size();
}
@Override
protected boolean onBalloonTap(int index) {
//---I cant call startActivity here as this class is not inhereted from Activity its //extended from a class that is extended from FrameLayout that you will find if you scroll down.
SubActivity sub = new SubActivity();
sub.startCustomActivity();
return true;
}
}
//--To start a new activity and to call startActivity method i have to create a new class and extends it from Activity...
public class SubActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void startCustomActivity(){
Intent Details = new Intent(getBaseContext(), Tab.class);
Details.putExtra("Id", 1327);
startActivity(Details);
}
}
Output:cant paste image directly the link is thismapView show overlay details when clicked
The image above is similar to what i am getting so when i click on the overlay this should startup a new intent activity where i want to show some details.
But when i click on it i get these errors. I am not sure if i am doing it the right way. I am calling the subActivity class when the image is clicked.
02-21 19:21:44.769: ERROR/AndroidRuntime(462): FATAL EXCEPTION: main
02-21 19:21:44.769: ERROR/AndroidRuntime(462): java.lang.NullPointerException
02-21 19:21:44.769: ERROR/AndroidRuntime(462): at android.content.ComponentName.<init>(ComponentName.java:75)
02-21 19:21:44.769: ERROR/AndroidRuntime(462): at android.content.Intent.<init>(Intent.java:2678)
02-21 19:21:44.769: ERROR/AndroidRuntime(462): at com.vouchacha.mvc.mapview.SubActivity.startCustomActivity(SubActivity.java:17)
02-21 19:21:44.769: ERROR/AndroidRuntime(462): at com.vouchacha.mvc.mapview.ItemizedOverlay.onBalloonTap(ItemizedOverlay.java:52)
02-21 19:21:44.769: ERROR/AndroidRuntime(462): at com.vouchacha.mvc.mapview.BalloonItemizedOverlay$1.onTouch(BalloonItemizedOverlay.java:177)
02-21 19:21:44.769: ERROR/AndroidRuntime(462): at android.view.View.dispatchTouchEvent(View.java:3762)
02-21 19:21:44.769: ERROR/AndroidRuntime(462): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:897)
02-21 19:21:44.769: ERROR/AndroidRuntime(462): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
02-21 19:21:44.769: ERROR/AndroidRuntime(462): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
02-21 19:21:44.769: ERROR/AndroidRuntime(462): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
02-21 19:21:44.769: ERROR/AndroidRuntime(462): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
02-21 19:21:44.769: ERROR/AndroidRuntime(462): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
02-21 19:21:44.769: ERROR/AndroidRuntime(462): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
02-21 19:21:44.769: ERROR/AndroidRuntime(462): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
02-21 19:21:44.769: ERROR/AndroidRuntime(462): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)
02-21 19:21:44.769: ERROR/AndroidRuntime(462): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1671)
very simple resolution for this:
replace this:
SubActivity sub = new SubActivity();
sub.startCustomActivity();
with this:
Intent Details = new Intent(context, Tab.class);
Details.putExtra("Id", 1327);
context.startActivity(Details);
use the context
variable you got from the MapView
you passed in your overlay class to start your activity.
这篇关于点击一个baloonOverlay当图形页面开始新的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!