Same widget on every Tab in TabHost - android

My xml is:
<?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:id="#+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/LinearLayout02"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</FrameLayout>
</LinearLayout>
<Button
android:id="#+id/btnsubmit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/btnsubmit" />
</LinearLayout>
and java file:
package com.harrbinger.formdesign;
import android.os.Bundle;
import android.app.TabActivity;
import android.content.Intent;
import android.view.Menu;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class FormActivity extends TabActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_form);
TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);
TabSpec tab1 = tabHost.newTabSpec("First Tab");
TabSpec tab2 = tabHost.newTabSpec("Second Tab");
TabSpec tab3 = tabHost.newTabSpec("Third tab");
tab1.setIndicator("Tab1");
tab1.setContent(new Intent(this,Generaldata.class));
tab2.setIndicator("Tab2");
tab2.setContent(new Intent(this,Production.class));
tab3.setIndicator("Tab3");
tab3.setContent(new Intent(this,Financial.class));
tabHost.addTab(tab1);
tabHost.addTab(tab2);
tabHost.addTab(tab3);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.form, menu);
return true;
}
}
I want The Submit Button to be available on every Tab.
The current xml is not working.
If I put it outside TabHost, the button is displayed but but above the tab host.
Help Please

Related

Tab view is missing when running the application

I had been trying to run the app i created. After running, it always give me a blank page instead of the tab view. Below are my design layout and the code in the fragment. I am using tab host in the fragment.
<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"
tools:context="com.example.redir.wealthtrack.UsageFragment">
<!-- TODO: Update blank fragment layout -->
<TabHost
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tabHost"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TabWidget
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#android:id/tabs"></TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="#+id/Tab1"
layout="#layout/fragment_tag1"
android:layout_width="match_parent"
android:layout_height="68dp">
</include>
<include
android:id="#+id/Tab2"
layout="#layout/fragment_tag2"
android:layout_width="match_parent"
android:layout_height="match_parent">
</include>
<include
android:id="#+id/Tab3"
layout="#layout/fragment_tag3"
android:layout_width="match_parent"
android:layout_height="match_parent">
</include>
<include
android:id="#+id/Tab4"
layout="#layout/fragment_tag4"
android:layout_width="match_parent"
android:layout_height="match_parent">
</include>
</FrameLayout>
</LinearLayout>
</TabHost>
</RelativeLayout>
My fragments used for Tab view
package com.example.redir.wealthtrack;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TabHost;
import com.example.redir.wealthtrack.Tabs.Tag1;
/**
* A simple {#link Fragment} subclass.
*/
public class UsageFragment extends Fragment {
public UsageFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_usage, container, false);
TabHost tab = (TabHost) view.findViewById(R.id.tabHost);
tab.setup();
TabHost.TabSpec spec1 = tab.newTabSpec("Tab 1");
spec1.setIndicator("Tab 1");
spec1.setContent(R.id.Tab1);
tab.addTab(spec1);
TabHost.TabSpec spec2 = tab.newTabSpec("Tab 2");
spec2.setIndicator("Tab 2");
spec2.setContent(R.id.Tab2);
tab.addTab(spec2);
TabHost.TabSpec spec3 = tab.newTabSpec("Tab 3");
spec3.setIndicator("Tab 3");
spec3.setContent(R.id.Tab3);
tab.addTab(spec3);
TabHost.TabSpec spec4 = tab.newTabSpec("Tab 4");
spec4.setIndicator("Tab 4");
spec4.setContent(R.id.Tab4);
tab.addTab(spec4);
return view;
}
}

Want to diaplay tabbar and listview in my launch activity

I want to display the tab bar and listview but when my main activity launched then my tab bar gets hided... so tell me what is the problem in my xml or my src file.
My problem is: My tab bar is not showing and only listview is showing on the full screen.
Here my lisview appears first and behind that my tab bar slightly visible.
Main Activity:(Here I am displaying tab host)
package com.example.testlist;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import android.app.Activity;
import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
public class MainActivity extends TabActivity implements OnTabChangeListener{
/*******************************/
//Test for tab bar
TabHost tabHost;
/*******************************/
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
/*setContentView(R.layout.list_view_layout);
ListView listview=(ListView)findViewById(R.id.listView1);
*/
setContentView(R.layout.layout_tab_bar);
// Get TabHost Refference
tabHost = getTabHost();
// Set TabChangeListener called when tab changed
tabHost.setOnTabChangedListener(this);
TabHost.TabSpec spec;
Intent intent;
/************* TAB1 (home)************/
// Create Intents to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, HomeTab.class);
spec = tabHost.newTabSpec("First").setIndicator("")
.setContent(intent);
//Add intent to tab
tabHost.addTab(spec);
/************* TAB2(alerts) ************/
intent = new Intent().setClass(this, Tab2.class);
spec = tabHost.newTabSpec("Second").setIndicator("")
.setContent(intent);
tabHost.addTab(spec);
/************* TAB3 (newsletters)************/
intent = new Intent().setClass(this, Tab3.class);
spec = tabHost.newTabSpec("Third").setIndicator("")
.setContent(intent);
tabHost.addTab(spec);
/************* TAB4(calendars) ************/
intent = new Intent().setClass(this, Tab4.class);
spec = tabHost.newTabSpec("Fourth").setIndicator("")
.setContent(intent);
tabHost.addTab(spec);
/************* TAB5 (more)************/
intent = new Intent().setClass(this, Tab5.class);
spec = tabHost.newTabSpec("Fifth").setIndicator("")
.setContent(intent);
tabHost.addTab(spec);
// Set drawable images to tab
tabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.homeicon);
tabHost.getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.alert_small_icon);
tabHost.getTabWidget().getChildAt(2).setBackgroundResource(R.drawable.newsl);
tabHost.getTabWidget().getChildAt(3).setBackgroundResource(R.drawable.menu_calendar);
tabHost.getTabWidget().getChildAt(4).setBackgroundResource(R.drawable.more_big);
// Set Tab1 as Default tab and change image
tabHost.getTabWidget().setCurrentTab(0);
}
#Override
public void onTabChanged(String tabId) {
}
}
HomeTab.java:(this class loads the content of first tab)
This class loads the content for the home tab where the contents related to home tab appears but my tab bar gets hided here.
package com.example.testlist;
import java.util.ArrayList;
import android.R.anim;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.ListView;
public class HomeTab extends Activity{
MyCustomAdapter myCustomAdapter;
Context context=HomeTab.this;
String optionName[]=new String[] {"Alerts","Events","Newsletters","News","Parent Info","Logins","Parent Teacher Interviews","Flexi School LunchOrder","Contact US","Kool Content"};
// String text2[]=new String[] {"sub1","sub2","sub3","sub4","sub1","sub2","sub3","sub4","sub1","sub2"};
//int image[]=new int[] {R.drawable.alert_small_icon,R.drawable.events,R.drawable.newsletter,R.drawable.newsletter,R.drawable.arrow_24,R.drawable.arrow_24,R.drawable.arrow_24,R.drawable.arrow_24,R.drawable.arrow_24,R.drawable.arrow_24};
int imageArrow[]=new int[]{R.drawable.right_arrow};
ArrayList<ListModel> mylist=new ArrayList<ListModel>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_view_layout);
ListView listview=(ListView)findViewById(R.id.listView1);
getDatainList();
listview.setAdapter(new MyCustomAdapter(context, mylist));
listview.setBackgroundColor(Color.WHITE);
}
private void getDatainList()
{
for(int i=0;i<10;i++)
{
ListModel li=new ListModel();
li.setOptionName(optionName[i]);
// li.setImage(image[i]);
li.setImageArrow(R.drawable.arrow);
mylist.add(li);
}
}
}
layout_tab_bar.java(This class displays the tab host and used in Main Activity)
<?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">
<RelativeLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</RelativeLayout>
</TabHost>
listview_layout.xml:
This file shows how the listview is added:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<!-- Header Starts -->
<RelativeLayout
android:id="#+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:paddingBottom="5dp"
android:paddingTop="5dp" >
<!-- Logo Start -->
<ImageView
android:id="#+id/menuimage"
android:layout_width="wrap_content"
android:layout_height="15dp"
android:src="#drawable/menuicon_big" />
<TextView
android:id="#+id/txt_Home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginLeft="22dp"
android:gravity="center"
android:text="HOME"
android:textColor="#android:color/black"
android:textSize="20sp" />
<View
android:layout_width="match_parent"
android:layout_height="1dp" />
</RelativeLayout>
<!-- Header Ends -->
<ImageView
android:id="#+id/stbernard"
android:layout_width="match_parent"
android:layout_height="60dp"
android:scaleType="fitXY"
android:src="#drawable/stbernard" />
<!-- <ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.01"
android:divider="#android:color/transparent"
android:dividerHeight="10.0sp" >
</ListView> -->
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</ListView>
</LinearLayout>
single_row.xml:
This file shows how the content inside listview appears for each item
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/rel">
<ImageView
android:id="#+id/imageviewArr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="21dp"
android:src="#drawable/arrow"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<View android:id="#+id/testView"
android:layout_height="1dp"
android:layout_width="match_parent"
android:background="#android:color/black"
/>
<TextView
android:id="#+id/txt_Options"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:text="text1"
android:textColor="#android:color/black"
android:textSize="20sp"
android:paddingLeft="2dp" />
</RelativeLayout>
it's because you declare the height of the content to fill the parent here
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
that's why the tabs is being overlapped by the content, what you need is android:layout_weight, so you need to change it to this
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
android:layout_weight will fill all the remaining space of the parent view so it won't overlap with each other

LocalActivityManager showing warning and Unable to Use TabHost in Activity- Application Stop when trying to Add Tab

What is error in this? I am getting warning on LocalActivityManager as:
The type LocalActivityManager is deprecated
Here is the code:
import android.os.Bundle;
import android.app.Activity;
import android.app.LocalActivityManager; **// Showing Cancel Warning**
import android.content.Intent;
import android.view.Menu;
import android.widget.TabHost;
public class MainActivity extends Activity {
TabHost tabHost;
#SuppressWarnings("deprecation")
LocalActivityManager mLocalActivityManager; **// Showing Cancel Warning**
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initTabs(savedInstanceState);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
#Override
protected void onResume() {
mLocalActivityManager.dispatchResume();
super.onResume();
}
#Override
protected void onPause() {
mLocalActivityManager.dispatchPause(isFinishing());
super.onPause();
}
#SuppressWarnings("deprecation")
private void initTabs(Bundle savedInstanceState) {
tabHost = (TabHost) findViewById(android.R.id.tabhost); // The activity TabHost
mLocalActivityManager = new LocalActivityManager(this, false);
mLocalActivityManager.dispatchCreate(savedInstanceState);
tabHost.setup(mLocalActivityManager);
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
intent = new Intent("com.plastemart.plastemartandroid");
spec = tabHost.newTabSpec("text").setIndicator("Latest")
.setContent(intent);
tabHost.addTab(spec); **// Getting Error Unfortunitly Application Stopped...Why?**
intent = new Intent("com.plastemart.plastemartandroid");
spec = tabHost.newTabSpec("text").setIndicator("Latest")
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent("com.plastemart.plastemartandroid");
spec = tabHost.newTabSpec("text").setIndicator("Latest")
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent("com.plastemart.plastemartandroid");
spec = tabHost.newTabSpec("text").setIndicator("Latest")
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(4);
}
My XML is as below
<LinearLayout 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:background="#ffffff"
android:orientation="vertical"
tools:context=".MainActivity" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="36dp"
android:background="#drawable/bg_plastemart_title" >
<TextView
android:id="#+id/textViewTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Plastemart.Com"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff" />
</RelativeLayout>
<TabHost
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" >
<HorizontalScrollView
android:id="#+id/horizontalScrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</TabWidget>
</HorizontalScrollView>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<LinearLayout
android:id="#+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</LinearLayout>
<LinearLayout
android:id="#+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</LinearLayout>
<LinearLayout
android:id="#+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</LinearLayout>
</LinearLayout>
</TabHost>
Where I am wrong? I am beginner in Android. Please Explain in Details if found solution.
I wrote above code by finding steps and solution on internet, but I am stucked here from past 4 days.
Please Help me.
This class was deprecated in API level 13. It is recommended to use Fragment and FragmentManager. If you not planning to use Fragment and FragmentManager APIs then you need to live with this warning message.
Please understand that this is a warning message only and not an error message. So you can still live with this. But recommended option is to use Fragment and FragmentManager APIs
You can see more details about the deprecated class here http://developer.android.com/reference/android/app/LocalActivityManager.html
Fragment - http://developer.android.com/reference/android/app/Fragment.html
FragmentManager - http://developer.android.com/reference/android/app/FragmentManager.html

Error in opening a new class on click of tab in Android application

I am developing an Android application in which I have a tab bar. I want that when I click on tab new class should open. How do I implement this? My main problem is when I pass the intent on clicking the tab. Then it's crashing.
I am posting my Java:
package com.solataire;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tab_host = (TabHost) findViewById(R.id.tab_host);
tab_host.setup();
TabSpec tabspec1 = tab_host.newTabSpec("TAB_1");
tabspec1.setIndicator("Tab 1");
tabspec1.setContent(R.id.first_tab);
tab_host.addTab(tabspec1);
TabSpec tabspec2 = tab_host.newTabSpec("TAB_2");
tabspec2.setIndicator("Tab 2");
tabspec2.setContent(R.id.second_tab);
tab_host.addTab(tabspec2);
TabSpec tabspec3 = tab_host.newTabSpec("TAB_3");
tabspec3.setIndicator("Tab 3");
tabspec3.setContent(R.id.third_tab);
tab_host.addTab(tabspec3);
tab_host.setCurrentTab(0);
}
}
My XML file is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabHost android:id="#+id/tab_host"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<TabWidget android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="#android:id/tabs"
android:layout_gravity="bottom" />
<FrameLayout android:id="#android:id/tabcontent"
android:layout_width="fill_parent" android:layout_height="fill_parent" >
<LinearLayout android:id="#+id/first_tab"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView android:layout_width="fill_parent"
android:layout_height="fill_parent" android:text="First Tab" />
<!-- Replace TextView with your layout content for this tab -->
</LinearLayout>
<LinearLayout android:id="#+id/second_tab"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView android:layout_width="fill_parent"
android:layout_height="fill_parent" android:text="Second Tab" />
<!-- Replace TextView with your layout content for this tab -->
</LinearLayout>
<LinearLayout android:id="#+id/third_tab"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView android:layout_width="fill_parent"
android:layout_height="fill_parent" android:text="One More Tab" />
<!-- Replace TextView with your layout content for this tab -->
</LinearLayout>
<LinearLayout android:id="#+id/edit_item_text_tab"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
</TabHost>
</LinearLayout>
Can anyone help me in this point?
You can try this.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, ArtistsActivity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("artists").setIndicator("Artists",
res.getDrawable(R.drawable.ic_tab_artists))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, AlbumsActivity.class);
spec = tabHost.newTabSpec("albums").setIndicator("Albums",
res.getDrawable(R.drawable.ic_tab_albums))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, SongsActivity.class);
spec = tabHost.newTabSpec("songs").setIndicator("Songs",
res.getDrawable(R.drawable.ic_tab_songs))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(2);
}
This is the xml:
<?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:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>

Android XML Layout issue

I want to make my layout for my first tab something like this:
I have already asked a question similar to this. I am getting stuck on the formatting:
This is what my code looks like:
<?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:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
<RelativeLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/simpleMode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding = "5dip"
android:layout_alignParentLeft="true"
android:src="#drawable/ic_tab_artists_grey" />
<TextView
android:id="#+id/right_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip"
android:layout_toRightOf="#+id/simpleMode"
android:gravity="right"
android:text="Description" />
</RelativeLayout>
</LinearLayout>
</TabHost>
My project runs but absolutely nothing shows up on the screen? Help is very much appreciated!!
Here is my activity class:
package com.joshi.remotedoc;
import android.app.TabActivity;
import android.os.Bundle;
import android.widget.TabHost;
import android.content.Intent;
import android.content.res.Resources;
public class Detailed_ModeActivity extends TabActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.patientmode);
Resources res = getResources();
// Resource object to get Drawables
TabHost tabHost = getTabHost();
// The activity TabHost
TabHost.TabSpec spec;
// Reusable TabSpec for each tab
Intent intent;
// Reusable Intent for each tab
// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, SimpleMode.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("simpleMode").setIndicator("simpleMode",
res.getDrawable(R.drawable.ic_tab_artists_white))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, DetailedMode.class);
spec = tabHost.newTabSpec("2ndtab").setIndicator("MySecondTab", res.getDrawable(R.drawable.something)) .setContent(intent);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("detailedMode").setIndicator("detailedMode",
res.getDrawable(R.drawable.ic_tab_artists_grey))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(2);
}
}
You need to properly define your layout, then you need to load your layout in the activity you are starting.
http://developer.android.com/guide/topics/ui/declaring-layout.html
First you create your XML
<?xml version="1.0" encoding="utf-8"?>
<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/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, I am a TextView" />
<Button android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, I am a Button" />
</LinearLayout>
Then you need to create the Java to load your XML in the oncreate method:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
}

Categories

Resources