Android MAP TO TABS
Hey I have tried a lot of ways of creating tabs which went ok, although when I add a map to it it crashes, I tried what this guy did here: http://joshclemm.com/blog/?p=86
My application crashes before any tabs appear. The code is below:
import android.content.Intent; import android.graphics.Color; import android.os.Bundle; import android.view.View; import android.widget.TabHost; import android.widget.TabHost.OnTabChangeListener; import android.widget.TabHost.TabContentFactory;
import com.google.android.maps.MapActivity; import com.google.android.maps.MapView;
public class Tabs extends MapActivity implements OnTabChangeListener {
private static final String HOME_TAG = "Home";
private static final String PLAYERS_TAG = "Players";
private static final String MAP_TAG = "Map";
private static final String TICKET_TAG = "Ticket";
private TabHost tabHost;
private MapView mapView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tabHost = (TabHost)findViewById(android.R.id.tabhost);
tabHost.setup();
tabHost.setOnTabChangedListener(this);
mapView = (MapView)findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
mapView.postInvalidate();
tabHost.addTab(tabHost.newTabSpec(HOME_TAG).setIndicator("Home").setContent(new Intent(this, Home.class)));
tabHost.addTab(tabHost.newTabSpec(PLAYERS_TAG).setIndicator("Players").setContent(new Intent(this, Players.class)));
tabHost.addTab(tabHost.newTabSpec(MAP_TAG).setIndicator("Venue").setContent(new TabContentFactory () {
public View createTabContent(String arg0) {
return mapView;
}
}));
for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
{
tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#00CC33"));
}
tabHost.getTabWidget().setCurrentTab(0);
tabHost.getTabWidget().getChildAt(0).setBackgroundColor(Color.parseColor("#3399FF"));
}
public void onTabChanged(String tabId) {
for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
{
tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#00CC33"));
}
tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#3399FF"));
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
}
And my manifest:
<application android:icon="@drawable/englandrugbyrose"
android:label="@string/app_name"
android:theme="@android:style/Theme.Light.NoTitleBar.Ful开发者_StackOverflow中文版lscreen">
<activity android:name=".Splash"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Tabs" />
<activity android:name=".Home" />
<activity android:name=".Players" />
<activity android:name=".Tickets" />
<activity android:name=".Map" />
<uses-library android:name="com.google.android.maps" />
</application>
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.INTERNET" />
Btw, my XML are in different XML files such as map.xml that contains the mapview id for loading the content, thats the only difference between mine and that other guys XML.
UPDATE: logcat
It points to line 35 at the mapView.setBuiltInZoomControls(true); With a nullpointer exception
Thanks.
Have you tried downgrading to API level 7? I had that problem with the mapView.setBuiltInZoom(true) when I was on API level 8. The exception stopped when I changed to API level 7.
精彩评论