Issue
I want to create an app consisting of two tabs each of which operates their own webview. I can create tabs but can't manage their webviews.
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; // Resusable 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, fbActivity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("fb").setIndicator("fb",
res.getDrawable(R.drawable.ic_tab_fb))
.setContent(intent);
tabHost.addTab(spec);
// Do the same for the other tabs
intent = new Intent().setClass(this, google.class);
spec = tabHost.newTabSpec("google").setIndicator("google",
res.getDrawable(R.drawable.ic_tab_google))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
Solution
first create tabactivity class
public class tabviews extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab);
TabHost tab = getTabHost();
TabSpec tab1 = (TabSpec) tab.newTabSpec("tb1");
TabSpec tab2 = (TabSpec) tab.newTabSpec("tb2");
tab1.setIndicator("Customer", null).setContent(
new Intent(this, webview1.class));
tab2.setIndicator("Item", null).setContent(
new Intent(this, webview2.class));
tab.addTab(tab1);
tab.addTab(tab2);
}
}
then create two activity class say webview1.class and webview2.class
public class webview1 extends Activity
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
WebView v = (WebView) findViewById(R.id.webView1);
v.loadUrl("http://www.google.com");
then create another class with same code. enter all three classes in manifest.xml
Answered By - Senthil
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.