How to switch to tabbed activity after splash screen..?

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

How to switch to tabbed activity after splash screen..?

Postby Pushpalata » Thu Sep 24, 2009 4:13 pm

Hello everyone,

I want to add tabbed page in my application after the splash screen.
In my project I hv written the code for splash screen containing an ImageView which appears for 4sec , after that I wish to hv home page for my appl & for that I need a layout containing tabs..so that I can give better access to my diff activities.

I tried a lot. I can do activity switching by adding 1 more java file in my src folder. bt it dint work here. After splash scrren it shows any another type of layout bt not TabWidget , why so?
plz help me!

my splash screens java file is like as follows:

package com.android.splash;
import android.widget.ImageView;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
//
public class splash extends Activity
{
private static final int STOPSPLASH = 0;

//time in milliseconds

private static final long SPLASHTIME = 4000;
private ImageView splash;

//handler for splash screen
private Handler splashHandler = new Handler()
{
/* (non-Javadoc) * @see android.os.Handler#handleMessage(android.os.Message)*/
@Override

public void handleMessage(Message msg)
{

switch (msg.what)
{

case STOPSPLASH:

//remove SplashScreen from view

splash.setVisibility(View.GONE);

setContentView([b][u]R.layout.tab[/u][/b]);

break;

}

super.handleMessage(msg);

}

};


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

@Override

public void onCreate(Bundle icicle)
{

super.onCreate(icicle);

setContentView(R.layout.main);

splash = (ImageView) findViewById(R.id.splash);

Message msg = new Message();

msg.what = STOPSPLASH;

splashHandler.sendMessageDelayed(msg, SPLASHTIME);

}
}

I hv adde one more java file (tab.java)in src :

package com.android.splash;
import android.app.Activity;
import android.app.TabActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.webkit.WebView;
import android.widget.TabHost;

public class tab extends TabActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
TabHost host=getTabHost();
host.addTab(host.newTabSpec("one").setIndicator("home") .setContent(new Intent(this, Restaurant.class)));

host.addTab(host.newTabSpec("two").setIndicator("settings") .setContent(new Intent(this, [u]Restaurant.class[/u])));
}
}
the Restaurant.class is another java file i added hving linear layout and some components on it..

main.xml:
<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:src="@drawable/splash"
android:layout_gravity="center"
android:id="@+id/splash"
/>
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>

this is what i did.....now i need ur help....!
Any Suggestions?
PUSHPALATA
Pushpalata
Freshman
Freshman
 
Posts: 6
Joined: Wed Sep 23, 2009 5:12 pm

Top

Postby yaj786 » Fri Sep 25, 2009 12:01 am

simple way:

Two activities: splash, tab;

open splash as your main activity.

splash :

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4. @Override
  5.  
  6. protected void onCreate(Bundle bundle)
  7.  
  8. {
  9.  
  10.      super.onCreate(bundle);
  11.  
  12.      setContentView(R.layout.splash);
  13.  
  14.      Thread sleeper = new Thread(sleepRunnable);
  15.  
  16.      sleeper.start();
  17.  
  18. }
  19.  
  20.  
  21.  
  22. private Runnable sleepRunnable = new Runnable(){
  23.  
  24.           private void run(){
  25.  
  26.                  try{
  27.  
  28.                         Thread.sleep(SPLASHTIME);
  29.  
  30.                  }
  31.  
  32.                  catch(Exception e)
  33.  
  34.                  {
  35.  
  36.                            e.printStackTrace();
  37.  
  38.                   }
  39.  
  40.  
  41.  
  42.                Intent i = new Intent(this, tab.class);
  43.  
  44.                i.setFlag(Activity.FLAG_ACTIVITY_CLEAR_TOP);
  45.  
  46.                startActivity(i);
  47.  
  48.           }
  49.  
  50. }
  51.  
  52.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
yaj786
Developer
Developer
 
Posts: 33
Joined: Fri Jul 10, 2009 7:37 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests