I’m designed a TabHost and its having 3 TabSpec’s so i need to add GridView for every TabSpec for that i created XML design for showing GridView and added like shown in below:
Creating TabHost:
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, Positions.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("positions").setIndicator("Positions",
res.getDrawable(R.drawable.buy))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, BuyPwr.class);
spec = tabHost.newTabSpec("buypwr").setIndicator("Buy Power",
res.getDrawable(R.drawable.buy))
.setContent(intent);
tabHost.addTab(spec);
intent = new Intent().setClass(this, Trades.class);
spec = tabHost.newTabSpec("trades").setIndicator("Trades",
res.getDrawable(R.drawable.buy))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
code for first TabSpec “Positions”
public class Positions extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.posgrid);
}
}
XML design for “posgrid.xml”
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow>
<TextView android:text="Current Position"
android:layout_width="100dp"
android:layout_column="0"
android:layout_weight="1"/>
<TextView android:text="Buy"
android:layout_width="30dp"
android:layout_column="1"
android:layout_weight="1">
</TextView>
<TextView android:text="Sell"
android:layout_width="30dp"
android:layout_column="2"
android:layout_weight="1">
</TextView>
</TableRow>
<ScrollView android:layout_height="120dp">
<TableLayout android:id="@+id/score_table"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow>
<TextView android:text="Al"
android:layout_width="100dp"
android:layout_column="0"
android:layout_weight="1">
</TextView>
<TextView android:text="1000"
android:layout_width="30dp"
android:layout_column="1"
android:layout_weight="1">
</TextView>
<TextView android:text="2"
android:layout_width="30dp"
android:layout_column="2"
android:layout_weight="1">
</TextView>
</TableRow>
</TableLayout>
</ScrollView>
</TableLayout>
</LinearLayout>
Also i added activity in manifest file like:
<activity android:name=".Positions" android:label="Pos"></activity>
So i didn’t get any errors but “posgrid” design is not showing in Postions TabSpec, plz any one help me.
Thanks,
nag.
possible reason can be Layout_height and layout_width is missing in some tags like upper TableRow and TextView in Lower TableRow .