I have made a tab container with TabHost, the layout xml file is like below:
<TabHost
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<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"
android:layout_marginTop="60dip" >
<fragment
android:id="#+id/tab1"
android:name="com.test.Tab1Fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<fragment
android:id="#+id/tab5"
android:name="com.test.Tab5Fragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
</TabHost>
In MainActivity, I init and add tab into activity in onCreate callback like this,
tabHost = (TabHost) findViewById(android.R.id.tabhost);
tabHost.setup();
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator(mRes.getString(R.string.tab1)).setContent(R.id.tab1));
tabHost.addTab(tabHost.newTabSpec("tab5").setIndicator(mRes.getString(R.string.tab5)).setContent(R.id.tab5));
On the tab changed, I want to find the current fragment, and do some init while current fragment is showing.
private OnTabChangeListener tabChangedListener = new OnTabChangeListener() {
public void onTabChanged(String tabid) {
Log.d(TAG, "tab changed " + tabid);
currentTab = tabid;
TabChangeCallback currentFragment = (TabChangeCallback) getFragmentManager().findFragmentByTag(currentTab);
if(currentFragment != null) {
currentFragment.onTabChanged(currentTabIndex);
} else {
Log.d(TAG, "get fragment null ");
}
}
};
Question is why getFragmentManager().findFragmentByTag(currentTab) is return null, and I couldn't call the fragment init code. thanks for your help.
I think if you are dealing with only fragment in the Tabhost then you better use FragmentTabHost. It will be more optimized and easy.
Example
And getting child fragment by Tag - link
This issue is because the fragemnt has not created at the time OnTabChnaged gets called.
Please check my answer here
Related
I am trying to switch between two WebViews in my layout with Android Java. The two WebViews load different urls when the oncreate method is called. The only problem am having is that the first webview shows up with the site content when oncreate is called but when I click the button that is supposed to show the next webview, it removes the current webview from view and then shows white screen. Help me resolve that, below is my layout file and the android java code behind file
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ViewSwitcher
android:layout_height="wrap_content"
android:id="#+id/viewSwitcher1"
android:layout_width="wrap_content">
<LinearLayout
android:id="#+id/view1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.webkit.WebView
android:id="#+id/webView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<LinearLayout
android:id="#+id/view2"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.webkit.WebView
android:id="#+id/webView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</ViewSwitcher>
<Button
android:id="#+id/button1"
android:text="Show Next"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>
and Android Java code for the behavior
public class MainActivity : AppCompatActivity
{
ViewSwitcher viewSwitcher;
private Button next;
protected WebView mywebview,webview2;
protected int mycount=0;
protected View view1, view2;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);
viewSwitcher = FindViewById<ViewSwitcher>(Resource.Id.viewSwitcher1);
next = FindViewById<Button>(Resource.Id.button1);
mywebview = FindViewById<WebView>(Resource.Id.webView1);
webview2 = FindViewById<WebView>(Resource.Id.webView2);
view1 = FindViewById<View>(Resource.Id.view1);
view2 = FindViewById<View>(Resource.Id.view2);
WebViewClient client = mywebview.WebViewClient;
mywebview.LoadUrl("https://www.upwork.com");
webview2.LoadUrl("https:www.sololearn.com");
//set the in and out animation for the viewswitcher
viewSwitcher.SetOutAnimation(this, Resource.Animation.abc_slide_out_top);
viewSwitcher.SetInAnimation(this, Resource.Animation.design_bottom_sheet_slide_in);
next.Click += Next_Click;
//hide the action bar
}
private void Next_Click(object sender, System.EventArgs e)
{
if (viewSwitcher.CurrentView != view1)
{
viewSwitcher.ShowPrevious();
}else if(viewSwitcher.CurrentView != view2)
{
viewSwitcher.ShowNext();
}
}
}
I'm writing my first android app using fragments but I can't figure out why it doesn't change view from main activity to fragment.
This is my mainActivity.java:
public class MainActivity extends AppCompatActivity {
Button fragment1_BTN, fragment2_BTN;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fragment1_BTN = findViewById(R.id.frag1_btn);
fragment2_BTN = findViewById(R.id.frag2_btn);
fragment1_BTN.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
replaceFragment(new Frag1());
}
});
fragment2_BTN.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
replaceFragment(new Frag2());
}
});
}
private void replaceFragment(Fragment fragment){
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
transaction.replace(R.id.frameLayout, fragment);
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
transaction.commit();
}}
This is my activity_main.xml:
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<FrameLayout
android:id="#+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="center">
<Button
android:id="#+id/therapists_btn"
android:layout_width="150dp"
android:layout_height="60dp"
android:backgroundTint="#color/teal_700"
android:text="button 1"
android:layout_marginRight="10dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/patients_btn" />
<Button
android:id="#+id/patients_btn"
android:layout_width="150dp"
android:layout_height="60dp"
android:layout_marginLeft="10dp"
android:backgroundTint="#color/teal_700"
android:text="button 2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/therapists_btn"
app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>
</FrameLayout> </androidx.constraintlayout.widget.ConstraintLayout>
The problem is that when I click on button 1 I see the view of first fragment and also of main activity.
How can I see only the fragment view?
your frameLayout container for Fragments is placed before LinearLayout, Fragments View is loaded into it and is visible, but also rest of Views is drawn after that (as order in XML) on top of it. just setVisibility(View.GONE) for this LinearLayout when you are loading Fragment (set for it some id and use findViewById as for buttons). another approach would be to put your LinearLayout inside container - you are using replace method so Fragment will remove your buttons, but in that case these are gone forever then and you don't have an easy option for bringing them back (with your current code - only whole Activity restart)
it would be way better (by design) if your Activity wouldn't have these buttons at all, only container, and on start would check if container has anything loaded (e.g. getChildCount()==0), if not then load some initial Fragment for preventing displaying empty Activity
I am an android beginner, just learning android static fragment concept, but after running my code getting app crash issue. Here is details:
MainActivity.java
package com.example.lalendrakumar.fragmentdemo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
activity_main.xml
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:weightSum="2">
<fragment
android:id="#+id/fragment1"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
<fragment
android:id="#+id/fragment2"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
So anyone can solve my problem.
I'm assuming you want the two fragments to fill the page. "fill_parent" has been replaced now by "match_parent." However, if you use this, in theory, the two fragments will overlap one over the other.
To split them in the screen, each will have to be adjusted to height zero. This is how each fragment's dimensions should read
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
You don't mentioned which layout you are using, but i assume you are using LinearLayout. LinearLayout take orientation horizontal by default, and you gave height and width to match_parent(fill_parent is deprecated now and replaced by match_parent)
Please find more information about LinearLayout on this link
Replace your code with following
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="2">
<fragment
android:id="#+id/fragment1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<fragment
android:id="#+id/fragment2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
try commenting out these lines in fragment class (if they are present )
/* #Override
public void onAttach(Context context) {
if (context instanceof OnFragmentInteractionListener) {
mListener = (OnFragmentInteractionListener) context;
} else {
throw new RuntimeException(context.toString()
+ " must implement OnFragmentInteractionListener");
}
}
*/
i am very new to Android Developing, have been developing mainly for ios for several years now but having problems in my first android app.
I am developing an app where at the beginning you have log in, so i created the UI and the login button and so far that works great, the app is able to connect to the database a download the necessary information for it to work via xml.
The downloaded Xml gives the items in the navigation drawer their names,
Basically all of the navigation drawer items should lead you to the same fragment, the content changes when loading the contents of the downloaded xml to it, but the window remains the same.
So in order to do this i created the navigation drawer items programmatically, added the ui for the fragment in a new xml.
When running the app everything works great, once you are logged in you are able to open the NavigationDrawer by swiping right, the right Items and names appear, but when clicking an item... nothing happens.
I used LOGE to know if the code was working and witch menu item was trying to open and it does return always the right menu item etc.
If there is a code in the fragment it executes the code and returns what its expected, but its simply not visible.
Here is my onNavigationItemSelected in MainActivity.
#Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
String title = item.getTitle().toString();
int order = (int) getMenuItemTag(item);
if (title != "Modos Personales" && title != "Home") {
Log.e("onNavigationItem: ", Integer.toString(order));
Fragment fragment = null;
Class fragmentClass;
fragmentClass = MainFragment.class;
try {
fragment = (Fragment) fragmentClass.newInstance();
android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.flContent, fragment);
fragmentTransaction.commit();
} catch (Exception e) {
e.printStackTrace();
}
//FragmentManager fragmentManager = getFragmentManager();
//android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
//fragmentManager.beginTransaction().replace(R.id.flContent, fragment).commit();
}
Here is the XML of my main activity "activity_main.xml"
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<FrameLayout
android:id="#+id/flContent"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<include
layout="#layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
Here is app_bar_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.paranoidinteractive.heimer.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay"
android:foreground="#mipmap/logo_menu"
android:foregroundGravity="center">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:theme="#style/Base.Theme.AppCompat.Light"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
Here is the XML of my Fragment "room_view.xml"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/room_view"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorScreen"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/textView"
android:layout_gravity="center_vertical" />
</LinearLayout>
and here is my fragmet "MainFragment.java"
public class MainFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
int number = 0;
if (inflater != null){
Log.e("INFLATER NO NULL: ", Integer.toString(number));
} else {
Log.e("INFLATER NULL: ", Integer.toString(number));
}
if (container != null){
Log.e("CONTAINTER NO NULL: ", Integer.toString(number));
} else {
Log.e("CONTAINER NULL: ", Integer.toString(number));
}
return inflater.inflate(R.layout.room_view, container, false);
}
}
And if you view the LOGCAT it allways returns:
01-26 16:27:36.771 9259-9259/com.paranoidinteractive.heimer E/INFLATER NO NULL:: 0
01-26 16:27:36.771 9259-9259/com.paranoidinteractive.heimer E/CONTAINER NO NULL:: 0
So i know its working and getting there but its simply not showing it.
I've followed all the tutorials available and read tons of questions and answers here but none of the answers have helped me so far so i Decided to post this question.
Thank you in advance for your help, hope you can assist me with this.
Sorry for the log post!
I'm working on an Android application with an Activity that uses a tab layout. There are two tabs which switch between the content being shown in some TextViews.
This means that the two tab specifications point to the same layout (linear) for content, R.id.plantilla:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<include layout="#layout/plantilla"/>
</FrameLayout>
</LinearLayout>
But this only works if I switch to tab 2 and back to 1, i.e when the activity launches, the Layout "plantilla" can't be seen before tabs are changed. This is my problem.
What's the most simple way to get around this?
PD: I have tried to duplicate the line
<include layout="#layout/plantilla">
in the tabhost xml, but in this case I can not access at the TextViews objects from the Java code using findViewById(R.id.someTextView);
I don't believe you can use include, I think you need to actually define your layout twice in the xml with different id tags.
Or you could simply define the container view and then add views to it programatically. I've done that before. Here's how I did it:
tablayout
<?xml version="1.0" encoding="utf-8"?>
<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"
android:padding="5dp" >
<TextView
android:id="#+id/setupheader"
android:layout_width="fill_parent"
android:layout_height="20dp"
android:textSize="15dp" />
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:gravity="bottom" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" >
<!-- General Info Tab -->
<LinearLayout
android:id="#+id/general_tab"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
<!-- Tool Tab -->
<LinearLayout
android:id="#+id/tool_tab"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ListView
android:id="#+id/list1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:drawSelectorOnTop="false" />
</LinearLayout>
<!-- Offset Tab -->
<LinearLayout
android:id="#+id/offset_tab"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ListView
android:id="#+id/list2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:drawSelectorOnTop="false" />
</LinearLayout>
<!-- Notes Tab -->
<LinearLayout
android:id="#+id/note_tab"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
Following is my tab activity (I've removed significant portions, but it should show well enough how I went about doing tabs without separate activites for each tab).
tabactivity
public class SetupDisplay extends TabActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.setupdetailmain);
Bundle extras = getIntent().getExtras();
RowId = extras.getLong("RowId");
StartTab = extras.getInt("StartTab");
// ***************************************************************
// Set up the tabs in the tabhost
// ***************************************************************
tabHost = getTabHost();
TabHost.TabSpec spec;
spec = tabHost.newTabSpec("General").setIndicator("General")
.setContent(R.id.general_tab);
tabHost.addTab(spec);
spec = tabHost.newTabSpec("Tools").setIndicator("Tools")
.setContent(R.id.tool_tab);
tabHost.addTab(spec);
spec = tabHost.newTabSpec("Offsets").setIndicator("Offsets")
.setContent(R.id.offset_tab);
tabHost.addTab(spec);
spec = tabHost.newTabSpec("Notes").setIndicator("Notes")
.setContent(R.id.note_tab);
tabHost.addTab(spec);
populateTabs(StartTab);
}
// ***************************************************************
// Clear views from linear layout tabs
// ***************************************************************
private void clearTabs() {
general.removeAllViews();
notes.removeAllViews();
}
// ***************************************************************
// Fill the tabs
// ***************************************************************
private void populateTabs(int TabShown) {
generaltab();
tooltab();
notestab();
offsettab();
tabHost.setCurrentTab(TabShown);
}
// ***************************************************************
// Fill the General tab
// ***************************************************************
private void generaltab() {
general = (LinearLayout) findViewById(R.id.general_tab);
String prgdisp = SETUPINFO_PGM1;
if (SETUPINFO_PGM2 != null) {
prgdisp = prgdisp + ", " + SETUPINFO_PGM2;
}
if (SETUPINFO_PGM3 != null) {
prgdisp = prgdisp + ", " + SETUPINFO_PGM3;
}
TextView programs = new TextView(this);
programs.setText("Program(s): " + prgdisp);
programs.setTextSize(20);
general.addView(programs);
if (SETUPINFO_KIT == null || SETUPINFO_KIT.equals("No Kit")) {
} else {
TextView kit = new TextView(this);
kit.setText("Kit: " + SETUPINFO_KIT);
kit.setTextSize(20);
general.addView(kit);
}
if (SETUPINFO_FIXTURE1 == null && SETUPINFO_FIXTURE2 == null) {
} else {
String fixtdisp = SETUPINFO_FIXTURE1;
if (SETUPINFO_FIXTURE2 != null) {
fixtdisp = fixtdisp + ", " + SETUPINFO_FIXTURE2;
}
TextView fixtures = new TextView(this);
fixtures.setText("Fixture(s): " + fixtdisp);
fixtures.setTextSize(20);
general.addView(fixtures);
TextView fixtureloc = new TextView(this);
fixtureloc.setText("Fixture Location: " + SETUPINFO_FIXTURELOC);
fixtureloc.setTextSize(20);
general.addView(fixtureloc);
}
if (SETUPINFO_VISE == null) {
} else {
TextView vise = new TextView(this);
vise.setText("Vise(s): " + SETUPINFO_VISE);
vise.setTextSize(20);
general.addView(vise);
}
}
// ***************************************************************
// Fill the Offset tab
// ***************************************************************
private void offsettab() {
wpccount = 0;
for (int i = 0; i < 20; i++) {
if (wpcdesc[i] != null) {
wpcdisplayhold[wpccount] = wpcid[i] + " - " + wpcdesc[i];
wpcidhold[wpccount] = wpcid[i];
wpcdeschold[wpccount] = wpcdesc[i];
wpccount++;
}
}
wpcdisplay = new String[wpccount];
for (int i = 0; i < wpccount; i++) {
wpcdisplay[i] = wpcdisplayhold[i];
}
mWPCView = (ListView) findViewById(R.id.list2);
mWPCView.setAdapter(new ColorizingListAdapter(SetupDisplay.this,
wpcdisplay, "Offset"));
registerForContextMenu(mWPCView);
}
// ***************************************************************
// Fill the Notes tab
// ***************************************************************
private void notestab() {
notes = (LinearLayout) findViewById(R.id.note_tab);
notestxt = new TextView(this);
notestxt.setText(SETUPINFO_NOTES);
notestxt.setTextSize(15);
notes.addView(notestxt);
}
}
Hope this helps.
Please remove the include tag from your xml layout and leave something simple:
<?xml version="1.0" encoding="utf-8"?>
<!-- Tab Host -->
<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">
<!-- Bottom tab bar -->
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_weight="1"/>
<!-- -5dip bottom margin for not showing the annoying bottom line -->
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="65dip"
android:layout_weight="0"
android:layout_marginBottom="-5dip"/>
</LinearLayout>
</TabHost>
And from your TabActivity class just put this in onCreate():
//Set tab host
tabHost = getTabHost();
//First Tab
TabSpec firstTabSpec = tabHost.newTabSpec("FirstTab");//title
firstTabSpec.setIndicator("FirstTab", getResources().getDrawable(R.drawable.item_first_tab)); //icon
Intent firstTabIntent = new Intent(this, FirstTab.class);//action
firstTabSpec.setContent(firstTabIntent);//set tab
//Second Tab
TabSpec secondTabSpec = tabHost.newTabSpec("SecondTab");//title
secondTabSpec.setIndicator("SecondTab", getResources().getDrawable(R.drawable.second_tab));//icon
Intent secondTabIntent = new Intent(this, FirstTab.class);//action
secondTabSpec.setContent(secondTabIntent);//set tab
//Add tabs to tab host
tabHost.addTab(firstTabSpec);//add first tab
tabHost.addTab(secondTabSpec);//add second tab which goes to your FirstTab.class
You can create different Activities for your tabs or use a single one.