PS. i am new in android and java programming.
i have this problem in my application it crashes when i clicked on my intent button which handles tab activity (the deprecated one), there are no errors with some warnings but i can't seem to figure out what i am doing wrong.
here is the code.
InformationActivity.class
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class InformationActivity extends TabActivity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_information);
// create the TabHost that will contain the Tabs
TabHost tabHost = (TabHost)findViewById(R.id.tabhost);
TabSpec tab1 = tabHost.newTabSpec("First Tab");
TabSpec tab2 = tabHost.newTabSpec("Second Tab");
// Set the Tab name and Activity
// that will be opened when particular Tab will be selected
tab1.setIndicator("Tab1");
tab1.setContent(new Intent(this,OfflineTab.class));
tab2.setIndicator("Tab2");
tab2.setContent(new Intent(this,OnlineTab.class));
/** Add the tabs to the TabHost to display. */
tabHost.addTab(tab1);
tabHost.addTab(tab2);
}
}
OfflineTab.class
import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.TextView;
public class OfflineTab extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
TextView tv=new TextView(this);
tv.setTextSize(25);
tv.setGravity(Gravity.CENTER_VERTICAL);
tv.setText("Contains R.E.D. e - Kit Offline module");
setContentView(tv);
}
}
OnlineTab.class
import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.TextView;
public class OnlineTab extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
TextView tv=new TextView(this);
tv.setTextSize(25);
tv.setGravity(Gravity.CENTER_VERTICAL);
tv.setText("This Is Tab2 Activity");
setContentView(tv);
}
}
activity_information.xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/tabhost">
<LinearLayout
android:id="@+id/LinearLayout01"
android:orientation="vertical"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
</FrameLayout>
</LinearLayout>
</TabHost>