안드로이드 개발 질문/답변
(글 수 45,052)
자바의 내용은 다음과 같습니다.
package com.example.han;
import android.app.TabActivity;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
@SuppressWarnings("deprecation")
public class TabhostXML extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tabhost_xml);
TabHost tabHost = getTabHost();
TabSpec tabSpecEnter = tabHost.newTabSpec("Enter").setIndicator("입학");
tabSpecEnter.setContent(R.id.Button01);
tabHost.addTab(tabSpecEnter);
TabSpec tabSpecSchool = tabHost.newTabSpec("School").setIndicator(
"생활");
tabSpecSchool.setContent(R.id.Button02);
tabHost.addTab(tabSpecSchool);
TabSpec tabSpecFood = tabHost.newTabSpec("Food").setIndicator("맛집");
tabSpecSchool.setContent(R.id.Button03);
tabHost.addTab(tabSpecFood);
TabSpec tabSpecSetting = tabHost.newTabSpec("Setting").setIndicator(
"설정");
tabSpecSetting.setContent(R.id.Button04);
tabHost.addTab(tabSpecSetting);
tabHost.setCurrentTab(0);
}
}
11-03 14:52:19.974: W/dalvikvm(379): threadid=1: thread exiting with uncaught exception (group=0x40015560)
11-03 14:52:19.984: E/AndroidRuntime(379): FATAL EXCEPTION: main
11-03 14:52:19.984: E/AndroidRuntime(379): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.han/com.example.han.TabhostXML}: java.lang.IllegalArgumentException: you must specify a way to create the tab content
11-03 14:52:19.984: E/AndroidRuntime(379): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
11-03 14:52:19.984: E/AndroidRuntime(379): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
11-03 14:52:19.984: E/AndroidRuntime(379): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
11-03 14:52:19.984: E/AndroidRuntime(379): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
11-03 14:52:19.984: E/AndroidRuntime(379): at android.os.Handler.dispatchMessage(Handler.java:99)
11-03 14:52:19.984: E/AndroidRuntime(379): at android.os.Looper.loop(Looper.java:130)
11-03 14:52:19.984: E/AndroidRuntime(379): at android.app.ActivityThread.main(ActivityThread.java:3683)
11-03 14:52:19.984: E/AndroidRuntime(379): at java.lang.reflect.Method.invokeNative(Native Method)
11-03 14:52:19.984: E/AndroidRuntime(379): at java.lang.reflect.Method.invoke(Method.java:507)
11-03 14:52:19.984: E/AndroidRuntime(379): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
11-03 14:52:19.984: E/AndroidRuntime(379): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
11-03 14:52:19.984: E/AndroidRuntime(379): at dalvik.system.NativeStart.main(Native Method)
11-03 14:52:19.984: E/AndroidRuntime(379): Caused by: java.lang.IllegalArgumentException: you must specify a way to create the tab content
11-03 14:52:19.984: E/AndroidRuntime(379): at android.widget.TabHost.addTab(TabHost.java:202)
11-03 14:52:19.984: E/AndroidRuntime(379): at com.example.han.TabhostXML.onCreate(TabhostXML.java:28)
11-03 14:52:19.984: E/AndroidRuntime(379): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-03 14:52:19.984: E/AndroidRuntime(379): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
11-03 14:52:19.984: E/AndroidRuntime(379): ... 11 more
11-03 14:52:19.994: W/ActivityManager(70): Force finishing activity com.example.han/.TabhostXML
11-03 14:52:20.518: W/ActivityManager(70): Activity pause timeout for HistoryRecord{406c91c0 com.example.han/.TabhostXML}
11-03 14:52:31.309: W/ActivityManager(70): Activity destroy timeout for HistoryRecord{406c91c0 com.example.han/.TabhostXML}
11-03 14:56:56.344: D/SntpClient(70): request time failed: java.net.SocketException: Address family not supported by protocol
11-03 14:57:20.054: I/Process(379): Sending signal. PID: 379 SIG: 9
11-03 14:57:20.104: I/ActivityManager(70): Process com.example.han (pid 379) has died.
11-03 14:57:20.324: W/InputManagerService(70): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@40795148
2012.11.04 12:27:11
private void addTab(int labelId, int drawableId, Intent targetIntent ) {
TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId);
View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false);
TextView title = (TextView) tabIndicator.findViewById(R.id.title);
title.setText(labelId);
title.setTypeface(null, Typeface.BOLD);
ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
icon.setImageResource(drawableId);
spec.setIndicator(tabIndicator);
spec.setContent(targetIntent);
tabHost.addTab(spec);
}
TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId);
View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false);
TextView title = (TextView) tabIndicator.findViewById(R.id.title);
title.setText(labelId);
title.setTypeface(null, Typeface.BOLD);
ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
icon.setImageResource(drawableId);
spec.setIndicator(tabIndicator);
spec.setContent(targetIntent);
tabHost.addTab(spec);
}
you must specify a way to create the tab content