Как использовать tabhost в андроиде для фрагментов управления .i имеет один активность и четыре Fragements и соответствующие XML files.i добавить свою вкладку в хост main_layout_activity.xml file.there я быть_наст другой Linnerlayout, я хочу заменить этот linnerlayout из Fragement.to, чтобы заменить эти Fragements, я должен использовать tabhost.help me please? Я нашел один код, но его messy.please найти ниже кода.Добавить фрагменты Tab хоста
final TabHost tabs= (TabHost) findViewById(R.id.tabhost);
tabs.setup();
TabHost.TabSpec spec=tabs.newTabSpec("tag1");
spec.setContent(R.id.fragment1);
spec.setIndicator("View Raves");
tabs.addTab(spec);
spec=tabs.newTabSpec("tag2");
spec.setContent(R.id.fragment2);
spec.setIndicator("My Badges");
tabs.addTab(spec);
tabs.setCurrentTab(0);
после того, как много идей, я поправьте мой код, как following.pls найти ниже
MainActivity.java
package com.example.testtabs;
import android.os.Bundle;
import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.app.TabActivity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabSpec;
import android.support.v4.app.Fragment;
import com.example.testtabs.R;
public class MainActivity extends TabActivity {
TabHost tab;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragementTest testfrag=new FragementTest();
FragmentManager manager=getFragmentManager();
FragmentTransaction transacti
transaction.add(R.id.my_layout1, testfrag, "");
transaction.commit();
tab= (TabHost) findViewById(android.R.id.tabhost);
tab.setup();
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:c
android:id="@+id/my_layout"
>
<LinearLayout
android:id="@+id/my_layout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_alignRight="@android:id/tabhost"
android:layout_marginTop="85dp"
android:orientati >
</LinearLayout>
<TabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientati >
<TabWidget
android:id="@android: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" >
</FrameLayout>
</LinearLayout>
</TabHost>
</RelativeLayout>
я хочу использовать конечные вкладки TabHost = (TabHost) findViewById (R.id.tabhost); но мой xml-файл «android: id =» @ android: id/tabhost », как он видит, тогда я не мог спросить вкладку хоста, есть ли какие-либо идеи? – VenushkaT
вы можете получить объект табуса, такой как this..tabHost = (TabHost) findViewById (android .R.id.tabhost); –
не из вашего файла R.java его из файла android R.java .. –