Want to diaplay tabbar and listview in my launch activity - android

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

Related

Same widget on every Tab in TabHost

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

How can i create Horizontal and Vertical tabs in android?

I am writing a code in Android to create Horizontal and Vertical tabs. In my code , i only able to create Horizontal tab , which is default.
XML Code
<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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#cccccc"
android:padding="5dp">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#cccccc"
android:padding="5dp">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:padding="5dp">
<GridView
android:id="#+id/gridView1"
android:numColumns="10"
android:gravity="center"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp"
android:stretchMode="columnWidth"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:horizontalSpacing="3dp"
android:verticalSpacing="3dp"
android:layout_width="1600dp"
android:layout_height="fill_parent"/>
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>
Java Code :
package com.example.tabsabc;
import java.util.ArrayList;
import android.os.Bundle;
import android.app.ActionBar;
import android.app.Activity;
import android.app.Fragment;
import android.app.TabActivity;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.TabHost;
import android.widget.TabWidget;
import android.widget.TextView;
public class MainActivity extends TabActivity implements TabHost.TabContentFactory {
ArrayList<String> names;
GridView gd;
BoxGrid gdv;
TabWidget tb1;
TabWidget tb2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gd = (GridView)findViewById(R.id.gridView1);
//tb1 = (TabWidget)findViewById(R.id.tabs1);
names = new ArrayList<String>();
final TabHost tabHost = getTabHost();
for (int i=1; i <= 10; i++) {
String name = "Tab " + i;
tabHost.addTab(tabHost.newTabSpec(name)
.setIndicator(name)
.setContent(this));
}
for(int i1=0;i1<150;i1++)
{
names.add(String.valueOf(i1));
}
ArrayAdapter gdv = new ArrayAdapter(this, android.R.layout.simple_list_item_1, names);
gd.setAdapter(gdv);
}
/** {#inheritDoc} */
public View createTabContent(String tag) {
final TextView tv = new TextView(this);
tv.setText("Content for tab with tag " + tag);
return tv;
}}
So, this is my above code and i can't find the place where can i add the vertical tab in the XML layout. I don't find any technique to do this.
Please let me know , suggest me some good solution.
I'll leave this here, because that's a more comfortable way than trying to style the TabWidget:
Looking for a universal TabHost style that will work on Android, HTC Sense, Samsung, etc. skins
But even better, use Fragments inside a ViewPager and not the old TabHost + TabWidget approach. It's the recommended way of doing Tabs in Android nowadays anyway.

How do i display a ListView with a header below another ListView all in Tab1 of TabHost?

I'm trying to put a ListView below another ListView in the first tab using tabhost.
The reason i want it like this is because i want to divide a list of trading cards by type so i guess creating sections or whatever.
Here is my .xml:
<?xml version="1.0" encoding="utf-8"?>
<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:orientation="vertical" >
<TextView
android:id="#+id/banlistdate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:text="Banlist Date: March, 2013"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF" />
<TabHost
android:id="#+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/banlistdate" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<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" >
<LinearLayout
android:id="#+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ListView
android:id="#+id/fLV1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF8B53"
tools:listheader="#layout/banlist_header_effectmonsters" >
</ListView>
<ListView
android:id="#+id/fLV2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#a086b7"
tools:listheader="#layout/banlist_header_fusionmonsters" >
</ListView>
</LinearLayout>
<LinearLayout
android:id="#+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="#+id/flv3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ListView>
</LinearLayout>
<LinearLayout
android:id="#+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ListView>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
Here is my the main java file to start the tabs and setup the ListViews:
package cybertech.productions.yugiohlibrary;
import java.util.ArrayList;
import java.util.Arrays;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;
public class Banlist extends Activity implements OnClickListener {
TabHost th;
Initializers initialMngr;
ArrayAdapter<String> listAdapter;
ListView forbiddenEMListView, forbiddenFListView;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.banlist);
th = (TabHost) findViewById(R.id.tabhost);
th.setup();
TabSpec specs = th.newTabSpec("tag1");
specs.setContent(R.id.tab1);
specs.setIndicator("Forbidden");
th.addTab(specs);
specs = th.newTabSpec("tag2");
specs.setContent(R.id.tab2);
specs.setIndicator("Semi-Limited");
th.addTab(specs);
specs = th.newTabSpec("tag3");
specs.setContent(R.id.tab3);
specs.setIndicator("Limited");
th.addTab(specs);
th.setCurrentTab(0);
// #BEGIN: Tab 1 ListViews
//Setup the "forbidden" ListView(s);
// ListView 1: Effect Monsters
forbiddenEMListView = (ListView) findViewById(R.id.fLV1);
ArrayList<String> forbiddenEMList = new ArrayList<String>();
forbiddenEMList.addAll(Arrays.asList(initialMngr.forbiddenEM));
listAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, forbiddenEMList);
View effectMon_header = View.inflate(this, R.layout.banlist_header_effectmonsters, null);
forbiddenEMListView.addHeaderView(effectMon_header);
forbiddenEMListView.setAdapter(listAdapter);
// ListView 2: Fusion Monsters
forbiddenFListView = (ListView) findViewById(R.id.fLV2);
ArrayList<String> forbiddenFList = new ArrayList<String>();
forbiddenFList.addAll(Arrays.asList(initialMngr.forbiddenF));
listAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, forbiddenFList);
View fusion_header = View.inflate(this, R.layout.banlist_header_fusionmonsters, null);
forbiddenFListView.addHeaderView(fusion_header);
forbiddenFListView.setAdapter(listAdapter);
// #END: Tab 1 ListViews
}
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
}
Thanks for any help.
You want to use an ExpandableListView. Use the group views to label the different categories or sections. Since you are using Arrays to back your lists, SimpleExpandableListAdapter should fit the bill nicely.

Android code to zoom and pan a Relative layout which contains text boxes, buttons, spinners, etc

I have zoomed into the layout easily but I also want to scroll the zoomed layout. I have been able to zoom but I want to also have scrolling after I zoom so that I can edit the values of the Widgets
Is there any way to do this ?
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RelativeLayout;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class MainActivity extends TabActivity {
View mainview;
int zoomed = 0;
TabHost th;
TabSpec one;
TabSpec two;
TabSpec three;
TabSpec four;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mainview = (RelativeLayout) findViewById(R.id.relLayout1);
th = getTabHost();
th.setup();
one = th.newTabSpec("One");
two = th.newTabSpec("Two");
three = th.newTabSpec("Three");
four = th.newTabSpec("Four");
one.setIndicator("One");
two.setIndicator("Two");
three.setIndicator("Three");
four.setIndicator("Four");
Intent a = new Intent(this, first.class);
Intent b = new Intent(this, second.class);
Intent c = new Intent(this, third.class);
Intent d = new Intent(this, fourth.class);
one.setContent(a);
two.setContent(b);
three.setContent(c);
four.setContent(d);
th.addTab(one);
th.addTab(two);
th.addTab(three);
th.addTab(four);
mainview.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
mainview.setPivotX(100);
mainview.setPivotY(100);
if (zoomed == 0) {
mainview.setScaleX(2f);
mainview.setScaleY(2f);
zoomed=1;
}
else{
mainview.setScaleX(1f);
mainview.setScaleY(1f);
zoomed=0;
}
}
});
}
}
And this is my layout :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/relLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TabHost
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="220dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<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" >
<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
android:id="#+id/tab4"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</RelativeLayout>

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