我尝试为我的应用制作自定义菜单标签,然后我找到了与我需要的stuf相似的来源,我结合了source1和source2这里的代码 但是当试图运行im得到FATAL EXCEPTION时这样:
06-03 16:30:05.305: E/AndroidRuntime(633): FATAL EXCEPTION: main
06-03 16:30:05.305: E/AndroidRuntime(633): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hynra.seribucandi/com.hynra.seribucandi.CandiAbang}: java.lang.IllegalArgumentException: you must specify a way to create the tab content
06-03 16:30:05.305: E/AndroidRuntime(633): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
06-03 16:30:05.305: E/AndroidRuntime(633): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
06-03 16:30:05.305: E/AndroidRuntime(633): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-03 16:30:05.305: E/AndroidRuntime(633): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
06-03 16:30:05.305: E/AndroidRuntime(633): at android.os.Handler.dispatchMessage(Handler.java:99)
06-03 16:30:05.305: E/AndroidRuntime(633): at android.os.Looper.loop(Looper.java:123)
06-03 16:30:05.305: E/AndroidRuntime(633): at android.app.ActivityThread.main(ActivityThread.java:3683)
06-03 16:30:05.305: E/AndroidRuntime(633): at java.lang.reflect.Method.invokeNative(Native Method)
06-03 16:30:05.305: E/AndroidRuntime(633): at java.lang.reflect.Method.invoke(Method.java:507)
06-03 16:30:05.305: E/AndroidRuntime(633): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-03 16:30:05.305: E/AndroidRuntime(633): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-03 16:30:05.305: E/AndroidRuntime(633): at dalvik.system.NativeStart.main(Native Method)
06-03 16:30:05.305: E/AndroidRuntime(633): Caused by: java.lang.IllegalArgumentException: you must specify a way to create the tab content
06-03 16:30:05.305: E/AndroidRuntime(633): at android.widget.TabHost.addTab(TabHost.java:202)
06-03 16:30:05.305: E/AndroidRuntime(633): at com.hynra.seribucandi.CandiAbang.setupTab(CandiAbang.java:55)
06-03 16:30:05.305: E/AndroidRuntime(633): at com.hynra.seribucandi.CandiAbang.onCreate(CandiAbang.java:36)
06-03 16:30:05.305: E/AndroidRuntime(633): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-03 16:30:05.305: E/AndroidRuntime(633): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
06-03 16:30:05.305: E/AndroidRuntime(633): ... 11 more
这里是java文件
package com.hynra.seribucandi;
import android.app.TabActivity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.TabHost.TabContentFactory;
import android.widget.TabHost.TabSpec;
import android.content.Intent;
import android.widget.ImageView;
public class CandiAbang extends TabActivity {
final static String INFO = "Info";
final static String MAP = "Map";
final static String GALL = "Gallery";
private TabHost tabHost;
private void setupTabHost() {
tabHost = (TabHost) findViewById(android.R.id.tabhost);
tabHost.setup();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.c_abang);
setupTabHost();
tabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider);
setupTab(new TextView(this), "INFO");
setupTab(new TextView(this), "MAP");
setupTab(new TextView(this), "GALL");
tabHost.setCurrentTab(0);
}
private void setupTab(final View view, final String tag) {
View tabview = createTabView(tabHost.getContext(), tag);
TabSpec setContent = tabHost.newTabSpec(tag).setIndicator(tabview);
if(tag.equals(INFO))
setContent.setContent(new Intent(this, AbangInfo.class));
else if(tag.equals(MAP))
setContent.setContent(new Intent(this, AbangMap.class));
else if(tag.equals(GALL))
setContent.setContent(new Intent(this, AbangGall.class));
tabHost.addTab(setContent);
}
private static View createTabView(final Context context, final String text) {
View view = LayoutInflater.from(context).inflate(R.layout.tab2_bg, null);
TextView tv = (TextView) view.findViewById(R.id.tabsText);
tv.setText(text);
return view;
}
}
这是布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabHost
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
</TabHost>
</LinearLayout>
对于使用此选项的背景选择器:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/tab2_selector"
android:padding="10dip"
android:gravity="center"
android:orientation="vertical"
>
<ImageView
android:id="@+id/tabsImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/tabsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:textSize="12dip"
android:textColor="@drawable/tab2_text"
/> </LinearLayout>
当我正在运行时,我只是得到异常警告:你必须指定一种创建标签内容的方法我该如何解决这个问题?帮我。先谢谢