Hi jouke, i am pretty new to android but let me clear a question that
arouse in my mind after reading your query...dont we need a (Spinner)
findViewById(R.id.spinner1); instance, an ArrayAdapter and setAdapter
called to the spinner instance we created to the spinner in layout...?
(Sorry if this is an idiotic question since i reached here searching
mTabHost error even after calling TabHost mTabHost, i am that much
naive)
Regards,
Sumit Asok.
jouke wrote:
> Hello all,
>
> I'm trying to use a tabhost and populate tabs using intents and
> activities. I've search all the examples I could find and I have
> something that gives the right layout but crashes as soon as I open a
> dialog. To reproduce it I made a small test program with 2 tabs, one
> filled using an xml layout and one using an intend. When I try to open
> the spinner in the second tab it crashes complaining about a null
> pointer. I'm sure I did something stupid but I can't figure out
> what ... please help.
>
> Jouke
>
> SOURCE:
> --- Test.java
> package com.jouke.test;
>
> import android.app.TabActivity;
> import android.content.Intent;
> import android.os.Bundle;
> import android.widget.TabHost;
>
> public class Test extends TabActivity {
> private TabHost mTabHost;
>
> @Override
> public void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> setContentView(R.layout.tab1);
> mTabHost = getTabHost();
>
> mTabHost.addTab(mTabHost.newTabSpec("Tab1")
> .setIndicator("Tab1")
> .setContent(R.id.tab1));
> Intent tab2 = new Intent(this.getApplicationContext
> (),tab2.class);
> mTabHost.addTab(mTabHost.newTabSpec("Tab2")
> .setIndicator("Tab2")
> .setContent(tab2));
> }
> }
> ---- Tab1.java
> package com.jouke.test;
>
> import android.app.TabActivity;
> import android.os.Bundle;
>
> public class tab1 extends TabActivity {
> @Override
> protected void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> setContentView(R.layout.tab1);
> }
> }
> ---- Tab2.java
> package com.jouke.test;
>
> import android.app.TabActivity;
> import android.os.Bundle;
>
> public class tab2 extends TabActivity {
> @Override
> protected void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> setContentView(R.layout.tab2);
> }
> }
> ---- Test.manifest
> <?xml version="1.0" encoding="utf-8"?>
> <manifest xmlns:android="http://schemas.android.com/apk/res/android"
> package="com.jouke.test"
> android:versionCode="1"
> android:versionName="1.0">
> <application android:icon="@drawable/icon" android:label="@string/
> app_name">
> <activity android:name=".Test"
> android:label="@string/app_name">
> <intent-filter>
> <action android:name="android.intent.action.MAIN" />
> <category
> android:name="android.intent.category.LAUNCHER" />
> </intent-filter>
> </activity>
> <activity android:name=".tab1">
> <intent-filter>
> <action android:name="android.intent.action.EMBEDDED" /
> >
> <category
> android:name="android.intent.category.LAUNCHER" />
> </intent-filter>
> </activity>
> <activity android:name=".tab2">
> <intent-filter>
> <action android:name="android.intent.action.EMBEDDED" /
> >
> <category
> android:name="android.intent.category.LAUNCHER" />
> </intent-filter>
> </activity>
> </application>
> <uses-sdk android:minSdkVersion="3" />
> </manifest>
> --- tab1.xml
> <?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">
> <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">
> <LinearLayout
> xmlns:android="http://schemas.android.com/apk/res/
> android"
> android:layout_width="wrap_content"
> android:layout_height="wrap_content"
> android:orientation="vertical"
> android:id="@+id/tab1">
> <TextView
> android:layout_width="wrap_content"
> android:layout_height="wrap_content"
> android:text="hallo" />
> <Spinner
> android:id="@+id/spinner1"
> android:layout_width="wrap_content"
> android:layout_height="wrap_content"
> android:entries="@array/spinnerItems"/>
> </LinearLayout>
> </FrameLayout>
> </LinearLayout>
> </TabHost>
> --- tab2.xml
> <?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">
> <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">
> <LinearLayout
> xmlns:android="http://schemas.android.com/apk/res/
> android"
> android:layout_width="wrap_content"
> android:layout_height="wrap_content"
> android:orientation="vertical"
> android:id="@+id/testlo">
> <TextView
> android:layout_width="wrap_content"
> android:layout_height="wrap_content"
> android:text="hallo" />
> <Spinner
> android:id="@+id/spinner1"
> android:layout_width="wrap_content"
> android:layout_height="wrap_content"
> android:entries="@array/spinnerItems"/>
> </LinearLayout>
> </FrameLayout>
> </LinearLayout>
> </TabHost>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---