I am creating a custom tabhost , on each tab spec open different activity . I want to get tab host on sub activity for finding Linear layout on tab host screen.
select_item.xml (Tab Host Layout)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<include
android:id="@+id/include1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
layout="@layout/outcom_actionbar" >
</include>
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<View
android:layout_width="fill_parent"
android:layout_height="0.5dip"
android:background="#fff" />
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="0dip"
android:layout_marginRight="0dip" />
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:background="#696969" />
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:background="#add23b" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
</TabHost>
</LinearLayout>
SelectItem.java (Custom Tab Host)
public class SelectItem extends TabActivity {
private TabHost mTabHost;
private void setupTabHost() {
mTabHost = (TabHost) findViewById(android.R.id.tabhost);
mTabHost.setup();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.select_item);
context=this;
setupTabHost();
mTabHost.getTabWidget().setDividerDrawable(null);
setupTab(new TextView(this), getString(R.string.Positions),Constants.ActivityName.Positions.toString());
setupTab(new TextView(this), getString(R.string.Sever),Constants.ActivityName.Sever.toString());
}
private void setupTab(final View view, final String tag,final String activityName) {
View tabview = createTabView(mTabHost.getContext(), tag);
TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(new TabContentFactory() {
public View createTabContent(String tag) {return view;}
});
Intent intent =null;
if(activityName.compareToIgnoreCase(Constants.ActivityName.Positions.toString())==0)
intent = new Intent().setClass(this, Items.class);
else if(activityName.compareToIgnoreCase(Constants.ActivityName.Sever.toString())==0)
intent = new Intent().setClass(this, Sever.class);
intent.putExtra(Constants.PROJECT_ID, projectId);
setContent.setContent(intent);
mTabHost.addTab(setContent);
}
private static View createTabView(final Context context, final String text) {
View view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null);
TextView tv = (TextView) view.findViewById(R.id.tabsText);
tv.setText(text);
return view;
}
}
On Server activity i want to get view of LinearLayout of select_item.xml file. But i am able to get details of tab host in Sever activity.
Please suggest me usable link or sample code.
Here is an example that may help you out. Click here
Look at the link and check out his project on GitHub. It really helped me out.