Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6865943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:07:01+00:00 2026-05-27T03:07:01+00:00

I have three 2 tab TabA and TabB. TabA displays value its ok. Now

  • 0

I have three 2 tab TabA and TabB. TabA displays value its ok. Now in Tab2 i have listview displaying the values. Whenever I click the listitem value that value have to pass to the next activity and new tab have to be created based on that value every time I click the listItem the tab should be generated. My problem is inside the click event of listitem intent = new Intent() is not supported. My code is as follows

public class FriendLists extends TabActivity {
       //Declarations

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.friendtab);

        connection=XMPPLogic.getInstance().getConnection();
        Resources res = getResources(); // Resource object to get Drawables
        TabHost tabHost = getTabHost();  // The activity TabHost
        TabHost.TabSpec spec;  // Reusable TabSpec for each tab
        Intent intent;  // Reusable Intent for each tab

            lv=(ListView) findViewById(R.id.footerlist);

        adapter = new ArrayAdapter<String>(this,R.layout.listitems,R.id.list_content, my_own_listarray);
        lv.setAdapter(adapter);
        //end of listing friends
        final AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener(){

            @Override
            public void onItemClick( AdapterView<?> parent, View v, int position, long id){
      //problem is here when i try to put intent and pass String S it creates a problem                     
                String S=group.get(position).toString();

//              spec = tabHost.newTabSpec(S).setIndicator(S,
//                        res.getDrawable(R.drawable.tab_friendlist))
//                    .setContent(null);
//              tabHost.addTab(spec);

                // set the message to display
                alertbox.setMessage(S).show();  

            }});

        // Create an Intent to launch an Activity for the tab (to be reused)
        intent = new Intent().setClass(this,Friends.class);

        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost.newTabSpec("friendlist").setIndicator("Friend List",
                          res.getDrawable(R.drawable.tab_friendlist))
                      .setContent(intent);
        tabHost.addTab(spec);

        tabHost.setCurrentTab(0);

        tabHost.addTab(tabHost.newTabSpec("onlinefriends").setIndicator("Online Friends",
                res.getDrawable(R.drawable.tab_friendlist))
                .setContent(R.id.footerlist));
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T03:07:02+00:00Added an answer on May 27, 2026 at 3:07 am

    From inside an anonymous inner class, you cannot refer to a non-final local variable (intent) that was declared outside of it.

    I assume you just need a temporary variable to hold the intent you want to pass to setContent. Just declare it inside onItemClick:

    Intent intent = new Intent( /* do your thing */ );
    spec = tabHost.newTabSpec(S).setIndicator(S,
               res.getDrawable(R.drawable.tab_friendlist))
           .setContent(intent);
    tabHost.addTab(spec);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have three subtabs under main tab, when I click main tab defauly I
I have three tabs with a specific filter content per tab. When i click
I have three tabs in one screen.by default i am displaying first tab data.
I have three tabs. When I press the tab button on the bottom, is
I have a UITabBar in my application with three tab bar items. At certain
I have a TabActivity with three tabs defined. The first tab is light-weight and
In my application, I have three tabs in the Action Bar. Tab A :
My app has three tabs, A, B, C that have three distinct activities. Tab
I have three tabs that each has its own Activity. The tabs are as
I have made a Tabbar based application in that i have three tab. each

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.