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 activitypackage 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
6 comments:
Thanks for this article
may be you may add the manifest and the layout used :)
Any change you could post complete code for this? I attempted to duplicate but got errors.
Thanks for the article.....
it's not working.. pls post that xml coding also.
thanks,vijay
please provide a link for download above code.
Thank U; Love U.
Need the manifest file for the above proj, can anyone help me out
Post a Comment