Search

Saturday, June 13, 2009

Android Program with Tab view and Intents class

Most of the time everybody uses VIEW as the content of the tab widget in android as it is easy and very light but some times it may be necessary to use activity as the content to the tab widget with intent class.

below i am taking two class with browser with different URL in each tab, below is the example code for the main activity


package com.ceveni.tabtest;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;

public class TabTest extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost mTabHost = getTabHost();
mTabHost.addTab(mTabHost.newTabSpec("one").setIndicator("ceveni").setContent(new Intent(this,Sz_dPush.class )));
mTabHost.addTab(mTabHost.newTabSpec("two").setIndicator("google").setContent(new Intent(this,Sz_Ssync.class )));
mTabHost.setCurrentTab(0);

}
}

below is the code for the activity which i will call as the intent in main class tab view below code contains a URL for this website and you can see the output in below link


package com.ceveni.tabtest;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class Sz_dPush extends Activity {
WebView browse;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
browse=new WebView(this);
setContentView(browse);
browse.loadUrl("http://www.ceveni.com");
}
}

And in other activity class i am adding a browser and URL for google


package com.ceveni.tabtest;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;

public class Sz_Ssync extends Activity{
WebView browse;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
browse=new WebView(this);
setContentView(browse);
browse.loadUrl("http://www.google.com");
}
}

below is the output and you can see the tab view you can see two different pages just like you do it on Firefox

this above code is working fine and i tested it on latest sdk with eclipse as the IDE if the above code does not work or if there is any suggestion let us know

6 comments:

Cyril said...

Thanks for this article
may be you may add the manifest and the layout used :)

Anonymous said...

Any change you could post complete code for this? I attempted to duplicate but got errors.

Thanks for the article.....

VIJAYAKUMAR M said...

it's not working.. pls post that xml coding also.

thanks,vijay

Anonymous said...

please provide a link for download above code.

Wpong Namprama said...

Thank U; Love U.

Sree said...

Need the manifest file for the above proj, can anyone help me out

Post a Comment

Other Interesting Articles



Related Article Widget by Yogith

Search Powered by Google