【发布时间】:2011-11-28 21:32:41
【问题描述】:
我有一个自定义选项卡主机,它使用 addTab() 方法而不是 tabspec。我在 MapView 中显示特定位置的选项卡之一。我遇到的问题是我的 tabhost 中设置 mapview 选项卡的行上的异常。
标签活动(出于保密原因删除了包):
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;
public class CustomTabHost extends TabActivity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tabhost);
setTabs() ;
}
private void setTabs()
{
addTab("Services", R.drawable.servicesicon, services.class);
addTab("Our Work", R.drawable.ourworkicon, ourwork.class);
addTab("RSS", R.drawable.rssicon, RSSReader.class);
addTab("Locate IML", R.drawable.locateicon, Locate.class);
addTab("Contact IML", R.drawable.contacticon, ContactUs.class);
}
private void addTab(String labelId, int drawableId, Class<?> c)
{
TabHost tabHost = getTabHost();
Intent intent = new Intent(this, c);
TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId);
View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tabs_bg, getTabWidget(), false);
TextView title = (TextView) tabIndicator.findViewById(R.id.title1);
title.setText(labelId);
ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon1);
icon.setImageResource(drawableId);
spec.setIndicator(tabIndicator);
spec.setContent(intent);
tabHost.addTab(spec);
}
}
地图活动:
import java.util.List;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
public class Locate extends MapActivity {
@Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.locateiml);
MapView mapview = (MapView) findViewById(R.id.locatemap);
mapview.setBuiltInZoomControls(true);
List<Overlay> mapOverlays = mapview.getOverlays();
Drawable drawable =this.getResources().getDrawable(R.drawable.locateicon);
Locateoverlay itemoverlay = new Locateoverlay(drawable, this);
GeoPoint point = new GeoPoint(382571066,-85751392);
OverlayItem overlayitem = new OverlayItem(point, "Interactive", null);
itemoverlay.addOverlay(overlayitem);
mapOverlays.add(itemoverlay);
}
protected boolean isRouteDisplayed()
{
return false;
}
}
还有一个叠加层,但这个问题不需要。我的问题是,我很确定我需要创建一个父活动来处理地图活动,但我不知道该怎么做。
【问题讨论】:
标签: android google-maps android-mapview parent-child android-tabhost