TabHost를 이용하여
3개의 탭에 한식 , 중식 ,일식
이런식으로 하여 각각의 탭에는 6개의 그림이 들어가는 것을 만들고 있는데요,
저는 XML을 TabHost를 쓰지않고 소스상에서 수정을 했는데요. Intent 로 Activity를 호출하는 방식으로 수정을 할려구요
1 2 3 페이지 그림이 뜨는데 탭이 처음에서 두번째 로 간다음 다시 세번째로 가면 에러가 나오고
처음에서 세번째로 가서 두번째로 가면 또 에러가 납니다.
1 -> 3 -> 1 -> 3 -> 1 , 1 -> 2 -> 1 -> 2 ->1이런식으론 잘되는데
1 ->3 ->2 , 1->2 -> 3 이렇게 세개 전체를 다 탭으로 이동할려면 에러가생기네요
final TabHost tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("tag")
.setIndicator("AMERICA")
.setContent(new Intent(this, AmericaFood.class)));
tabHost.addTab(tabHost.newTabSpec("tab2")
.setIndicator("CHINA")
.setContent(new Intent(this, ChinaFood.class)));
tabHost.addTab(tabHost.newTabSpec("tab3")
.setIndicator("NIPPON")
.setContent(new Intent(this, NipponFood.class)));
tabHost.setCurrentTab(0);
을
final TabHost tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("tag")
.setIndicator("AMERICA")
.setContent(new Intent(this, AmericaFood.class)));
tabHost.addTab(tabHost.newTabSpec("tab2")
.setIndicator("CHINA")
.setContent(new Intent(this, ChinaFood.class)));
tabHost.addTab(tabHost.newTabSpec("tab3")
.setIndicator("NIPPON")
.setContent(new Intent(this, ChinaFood.class))); // 수정
tabHost.setCurrentTab(0);
와
final TabHost tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("tag")
.setIndicator("AMERICA")
.setContent(new Intent(this, AmericaFood.class)));
tabHost.addTab(tabHost.newTabSpec("tab2")
.setIndicator("CHINA")
.setContent(new Intent(this, NipponFood.class))); // 수정
tabHost.addTab(tabHost.newTabSpec("tab3")
.setIndicator("NIPPON")
.setContent(new Intent(this, NipponFood.class)));
tabHost.setCurrentTab(0);
이런식으로 수정하니깐 아무문제없이 잘돌아갑니다.
XML 메인은없고 3개의 XML 을 쓰는데 이렇습니다.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TableLayout
android:id="@+id/tab1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="8px"
>
<TableRow>
<ImageView
android:id="@+id/image1_1"
android:layout_width="100px"
android:layout_height="100px"
android:maxWidth="100px"
android:maxHeight="100px"
android:layout_weight="1"
android:src="@drawable/america1"
/>
<ImageView
android:id="@+id/image1_2"
android:layout_width="100px"
android:layout_height="100px"
android:maxWidth="100px"
android:maxHeight="100px"
android:layout_weight="1"
android:src="@drawable/america2"
/>
<ImageView
android:id="@+id/image1_3"
android:layout_width="100px"
android:layout_height="100px"
android:maxWidth="100px"
android:maxHeight="100px"
android:layout_weight="1"
android:src="@drawable/america3"
/>
</TableRow>
<TableRow>
<Button
android:id="@+id/button1_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/open"
/>
<Button
android:id="@+id/button1_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/open"
/>
<Button
android:id="@+id/button1_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/open"
/>
</TableRow>
<TableRow>
<ImageView
android:id="@+id/image1_4"
android:layout_width="100px"
android:layout_height="100px"
android:maxWidth="100px"
android:maxHeight="100px"
android:layout_weight="1"
android:src="@drawable/america4"
/>
<ImageView
android:id="@+id/image1_5"
android:layout_width="100px"
android:layout_height="100px"
android:maxWidth="100px"
android:maxHeight="100px"
android:layout_weight="1"
android:src="@drawable/america5"
/>
<ImageView
android:id="@+id/image1_6"
android:layout_width="100px"
android:layout_height="100px"
android:maxWidth="100px"
android:maxHeight="100px"
android:layout_weight="1"
android:src="@drawable/america6"
/>
</TableRow>
<TableRow>
<Button
android:id="@+id/button1_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/open"
/>
<Button
android:id="@+id/button1_5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/open"
/>
<Button
android:id="@+id/button1_6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/open"
/>
</TableRow>
</TableLayout>
</LinearLayout>
세개다 비슷하다 보심되요 ㅠ