(중요 유일한 부분 ...) : 여기
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/tWelcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/bNewTask"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Task" />
<TabHost
android:id="@+id/myTabs"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ListView>
</LinearLayout>
<LinearLayout
android:id="@+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/tTest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
지금 내 활동 코드 :
그래서 여기 내 XML이다.
TabActivity를 사용하는 경우 (요구 사항이 아니지만 더 쉽게 작업 할 수 있음) 탭 호스트의 ID는 android:id="@android:id/tabhost"
이어야합니다.
나는 탭 호스트가 루트 노드 여야한다고도 보았습니다. 나는 안드로이드 워드 프로세서를 사용하여 확인할 수 없습니다. 나는 다른 모든 길들이 실패한 후에 (또는 누군가가 그것이 사실임을 확인한 후에)이 변화를 만들 것입니다.
TabActivity를 사용하는 경우 id로 탭 호스트를 참조하거나 setup() 메소드를 사용할 필요가 없습니다. setup() 메소드를 사용하고있는 것을 보았습니다 만, 액티비티가 TabActivity인지 알 수는 없습니다. 그렇다면 문제가 원인 일 수 있습니다.
다음
내가 탭 레이아웃 설정에 사용하는 방법이며 나를 위해 작동합니다. 탭 호스트는 레이아웃의 루트 노드로 가정하고 id는
android:id/tabhost
이며 TabActivity입니다.
tabhost 코드 :이 도움이
public class Tabs extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_layout);
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
spec = tabHost.newTabSpec("tag1").setIndicator("All").setContent(R.id.tab1);
tabHost.addTab(spec);
spec = tabHost.newTabSpec("tag2").setIndicator("Personal").setContent(R.id.tab2);
tabHost.addTab(spec);
}
}
희망! 문제가 해결되면 대답을 수락하려면 확인 표시를 클릭하십시오. http://developer.android.com/resources/tutorials/views/hello-tabwidget.html
그것은 정보 탭에 대한 요구 사항을 가지고 있으며,이 샘플 코드를 많이 제공합니다
: 모든 탭 요소가 제안 된 안드로이드 식별자가 될 수 있도록
특히, 나는 ID를 변경거야? –