Hi there, I am very new to Android and I have been working through various tutorials, so far everything's been fine until I started with the Android Tab Tutorial. I still have the "force close" error, even though I have tried several solutions that I found on the web. If someone could help me find where I am have done something wrong in my code, that would be absolutely fantastic. I am really getting desperate.
So here is what I have done and thank you so much in advance...
My [edited] Manifest.xml:
The main.xml:
The ic_tab_share.xml and ic_tab_edit.xml:
The GalleryView.java file:
and finally the ShareGalleryView.java and the EditGalleryView.java:
So here is what I have done and thank you so much in advance...
My [edited] Manifest.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mobilevideoeditor.moved"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".ShareGalleryView" android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar"> </activity>
<activity android:name=".EditGalleryView" android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar"> </activity>
<activity android:name=".GalleryView" android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<activity>
</application>
</manifest>
The main.xml:
Code:
<?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>
The ic_tab_share.xml and ic_tab_edit.xml:
Code:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- When selected, use ic_tab_share (grey icon) -->
<item android:drawable="@drawable/ic_tab_share"
android:state_selected="true" />
<!-- When not selected, use ic_tab_share_unselected (white icon)-->
<item android:drawable="@drawable/ic_tab_share_unselected" />
</selector>
The GalleryView.java file:
Code:
package com.mobilevideoeditor.moved;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;
public class GalleryView extends TabActivity {
/** Called when the activity is first created. */
@Override
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; // 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, EditGalleryView.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("edit").setIndicator("Edit",
res.getDrawable(R.drawable.ic_tab_edit))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, ShareGalleryView.class);
spec = tabHost.newTabSpec("share").setIndicator("Share",
res.getDrawable(R.drawable.ic_tab_share))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
}
and finally the ShareGalleryView.java and the EditGalleryView.java:
Code:
package com.mobilevideoeditor.moved;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class EditGalleryView extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView textview = new TextView(this);
textview.setText("This is the Edit tab!");
setContentView(textview);
}
}