in Education by
I am developing an Android application in which I have a tab bar. I want that when I click on tab new class should open. How do I implement this? My main problem is when I pass the intent on clicking the tab. Then it's crashing. I am posting my Java: package com.solataire; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.widget.TabHost; import android.widget.TabHost.TabSpec; public class MainActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TabHost tab_host = (TabHost) findViewById(R.id.tab_host); tab_host.setup(); TabSpec tabspec1 = tab_host.newTabSpec("TAB_1"); tabspec1.setIndicator("Tab 1"); tabspec1.setContent(R.id.first_tab); tab_host.addTab(tabspec1); TabSpec tabspec2 = tab_host.newTabSpec("TAB_2"); tabspec2.setIndicator("Tab 2"); tabspec2.setContent(R.id.second_tab); tab_host.addTab(tabspec2); TabSpec tabspec3 = tab_host.newTabSpec("TAB_3"); tabspec3.setIndicator("Tab 3"); tabspec3.setContent(R.id.third_tab); tab_host.addTab(tabspec3); tab_host.setCurrentTab(0); } } My XML file is: <?xml version="1.0" encoding="utf-8"?> <!-- Replace TextView with your layout content for this tab --> <!-- Replace TextView with your layout content for this tab --> <!-- Replace TextView with your layout content for this tab --> Can anyone help me in this point? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You can try this. 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, ArtistsActivity.class); // Initialize a TabSpec for each tab and add it to the TabHost spec = tabHost.newTabSpec("artists").setIndicator("Artists", res.getDrawable(R.drawable.ic_tab_artists)) .setContent(intent); tabHost.addTab(spec); // Do the same for the other tabs intent = new Intent().setClass(this, AlbumsActivity.class); spec = tabHost.newTabSpec("albums").setIndicator("Albums", res.getDrawable(R.drawable.ic_tab_albums)) .setContent(intent); tabHost.addTab(spec); intent = new Intent().setClass(this, SongsActivity.class); spec = tabHost.newTabSpec("songs").setIndicator("Songs", res.getDrawable(R.drawable.ic_tab_songs)) .setContent(intent); tabHost.addTab(spec); tabHost.setCurrentTab(2); } This is the xml: <?xml version="1.0" encoding="utf-8"?>

Related questions

0 votes
    I am developing an Android application in which I have a tab bar. I want that when I click on ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 11, 2022 in Education by JackTerrance
0 votes
    Click on the ________ tab to add chart details like titles, labels, legend etc. Design Layout Format Select the correct answer from above options...
asked Nov 26, 2021 in Education by JackTerrance
0 votes
    what happens when you click on the following in costume tab:edit button, copy button, x button Select the correct answer from above options...
asked Nov 26, 2021 in Education by JackTerrance
0 votes
    what happens when you click on the following in costume tab:edit button, copy button, x button Select the correct answer from above options...
asked Nov 25, 2021 in Education by JackTerrance
0 votes
    what happens when you click on the following in costume tab:edit button, copy button, x button Select the correct answer from above options...
asked Nov 25, 2021 in Education by JackTerrance
0 votes
    I'm making a game as an android app in which the user clicks on buttons to change its color and ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    I used a webview to load up a webpage. Is there a way to listen click action to know what hyper ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    Which tab will you click to use the Track Changes feature? Select the correct answer from above options...
asked Dec 31, 2021 in Education by JackTerrance
0 votes
    the………….. . toolbar in Microsoft word contains the tool buttons for opening and existing or a new blank word document Select the correct answer from above options...
asked Dec 22, 2021 in Education by JackTerrance
0 votes
    What are the shortcuts key using keyboard for opening a new document?..please anyone? Select the correct answer from above options...
asked Dec 14, 2021 in Education by JackTerrance
0 votes
    To open a new file usese has to click on which menu and option? class 7 computer Select the correct answer from above options...
asked Dec 10, 2021 in Education by JackTerrance
0 votes
    To start with the new package in RStudio, double-click the pkgname.Rproj file that _______ (a) Delete() ... of R Programming Select the correct answer from above options...
asked Feb 11, 2022 in Education by JackTerrance
0 votes
    How does android track the application on process?...
asked Jan 14, 2021 in Technology by JackTerrance
0 votes
    Divide the class in 5 groups, where each group will represent one of the five tabs Entrance', Emphasis', ... OF THE SECTION EFFECTS Select the correct answer from above options...
asked Nov 27, 2021 in Education by JackTerrance
...