I have an Android app that uses tabs for its start menu.  The tabs don't 
display when I port the app to a Kindle Fire.  Here's the code:

    <?xml version="1.0" encoding="utf-8"?>
<ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"; 
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:isScrollContainer="true" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <TabHost
            android:id="@+id/tabhost"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <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/Beginning"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:orientation="vertical" >
                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/Intermediate"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:orientation="vertical" >
                    </LinearLayout>

                    <LinearLayout
                        android:id="@+id/Advanced"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:orientation="vertical" >
                    </LinearLayout>
                </FrameLayout>
            </LinearLayout>
        </TabHost>
    </LinearLayout>

</ScrollView>

    package com.myproject.project;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.content.res.AssetManager;
import android.database.Cursor;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.os.Environment;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;
import android.widget.Toast;

public class TabsTestActivity extends Activity {

 /** Called when the activity is first created. */

 public static final String KEY_ROWID = "_id";
 public static final String KEY_NAME = "name";
 public static final String KEY_LEVEL = "level";
 public static final String KEY_CHART = "charted";
 public String extStorageDirectory = Environment
   .getExternalStorageDirectory().toString();

 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  PopulateDatabase();

  CopyVideoFiles();

  TabHost tabhost = (TabHost) findViewById(R.id.tabhost);
  tabhost.setup();

  TabSpec spec_beg = tabhost.newTabSpec("Beginning");
  spec_beg.setContent(R.id.Beginning);
  TextView txtTabInfo = new TextView(this);
  txtTabInfo.setText("JUST STARTING");
  Typeface font = Typeface.createFromAsset(getAssets(), "danielbd.ttf");
  txtTabInfo.setTypeface(font);
  txtTabInfo.setGravity(Gravity.CENTER);
  txtTabInfo.setHeight(50);
  txtTabInfo.setBackgroundColor(Color.parseColor("#CCDE8A"));
  txtTabInfo.setTextColor(Color.parseColor("#262405"));
  spec_beg.setIndicator(txtTabInfo);

  TabSpec spec_int = tabhost.newTabSpec("Intermediate");
  spec_int.setContent(R.id.Intermediate);
  txtTabInfo = new TextView(this);
  txtTabInfo.setText("GETTING THERE");
  txtTabInfo.setTypeface(font);
  txtTabInfo.setGravity(Gravity.CENTER);
  txtTabInfo.setHeight(50);
  txtTabInfo.setBackgroundColor(Color.parseColor("#CCDE8A"));
  txtTabInfo.setTextColor(Color.parseColor("#262405"));
  spec_int.setIndicator(txtTabInfo);

  TabSpec spec_adv = tabhost.newTabSpec("Advanced");
  spec_adv.setContent(R.id.Advanced);
  txtTabInfo = new TextView(this);
  txtTabInfo.setText("REALLY GOOD");
  txtTabInfo.setTypeface(font);
  txtTabInfo.setGravity(Gravity.CENTER);
  txtTabInfo.setHeight(50);
  txtTabInfo.setBackgroundColor(Color.parseColor("#CCDE8A"));
  txtTabInfo.setTextColor(Color.parseColor("#262405"));
  spec_adv.setIndicator(txtTabInfo);

  // get data from database, create buttons and name them
  SQLData myTable = new SQLData(this);
  myTable.open();
  Cursor c = myTable.getallData();

  int iRow = c.getColumnIndex(KEY_ROWID);
  int iName = c.getColumnIndex(KEY_NAME);
  int iLevel = c.getColumnIndex(KEY_LEVEL);

  // create the buttons
  for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
   final String RowNum = c.getString(iRow);
   String Name = c.getString(iName);
   final String Level = c.getString(iLevel);
   Button button = new Button(this);
   button.setText(Name);
   button.setHeight(20);
   button.setTextColor(Color.BLACK);
   button.setBackgroundColor(Color.parseColor("#A89E0A"));
   button.setHighlightColor(Color.WHITE);
   button.setTypeface(font);
   button.setOnClickListener(new Button.OnClickListener() {

    public void onClick(View v) {
     Intent choice = new Intent(getApplicationContext(),
       com.myproject.project.myclass.class);
     Bundle dataBundle = new Bundle();
     dataBundle.putString("RowID", RowNum);
     dataBundle.putString("Level", Level);
     choice.putExtras(dataBundle);
     try {
      startActivity(choice);
     } catch (Exception e) {
      Dialog d = new Dialog(getApplicationContext());
      d.setTitle("TabsTestActivity line 131");
      TextView tv = new TextView(getApplicationContext());
      tv.setText(e.toString());
      d.setContentView(tv);
      d.show();
     } finally {

     }
    }
   });

   LinearLayout lbeg = (LinearLayout) findViewById(R.id.Beginning);
   LinearLayout lint = (LinearLayout) findViewById(R.id.Intermediate);
   LinearLayout ladv = (LinearLayout) findViewById(R.id.Advanced);

   if (Level.equals("Beginning"))
    lbeg.addView(button);
   else if (Level.equals("Intermediate"))
    lint.addView(button);
   else if (Level.equals("Advanced"))
    ladv.addView(button);
  }

  tabhost.addTab(spec_beg);
  tabhost.addTab(spec_int);
  tabhost.addTab(spec_adv);

  myTable.close();

 }}

Does anyone know why? The tabs and their contents show up fine in the 
emulator and on my Android phone.  Thanks!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to