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 3987820
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:10:45+00:00 2026-05-20T06:10:45+00:00

I have 2 buttons, when you click them, it launches a new listView activity.

  • 0

I have 2 buttons, when you click them, it launches a new listView activity. Before it starts the activity, I make a bundle, putString depending on which button was clicked and putExtras.

In the listView activity, I have two string arrays. I want the ArrayAdapter to getExtras and read the variable so I know which button was pressed to get there and then I’ll know which string array to load into the ArrayAdapter.

Here is my idea but the ArrayAdapter doesn’t accept the string, even though s = the name of one of the string arrays. Also, I’m not sure if I’m approaching this in the best way.

Bundle b = this.getIntent().getExtras();
    String s = b.getString("TEXT");
    setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, s));
  • 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-20T06:10:46+00:00Added an answer on May 20, 2026 at 6:10 am

    The array adapter takes a list of objects as a third parameter as the documentation on public constructors suggests (Source Developer Android):

    Constructor
    ArrayAdapter(Context context, int textViewResourceId, T[] objects)
    Constructor
    ArrayAdapter(Context context, int resource, int textViewResourceId, T[] objects)
    Constructor
    ArrayAdapter(Context context, int textViewResourceId, List<T> objects)
    Constructor
    ArrayAdapter(Context context, int resource, int textViewResourceId, List<T> objects)
    

    So you just need to encapsulate your String in an array (even if you have only one string to display).

    ArrayList<String> arr = new ArrayList<String>();
    arr.add(s);
    setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, arr));
    

    EDIT
    Ok. Why don’t you try a very basic if-else statement? Like:

    ArrayList<String> arrButton1 = new ArrayList<String>();
    ArrayList<String> arrButton2 = new ArrayList<String>();
    ArrayList<String> arrToChoose;
    if(s.equals("button1")) { 
      arrToChoose = arrButton1;
    } else if(s.equals("button2")) {
      arrToChoose = arrButton2;
    }
    setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, arrayToChoose));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 4 buttons that when click starts a new activity class. This works
I have some radio buttons on which I have applied css to align them.
I have two image buttons with Click events assigned to them. There is code
I have two button name A, and B want to click them equal to
I have multiple buttons on a page and I want to simulate a click
I have these buttons inside a div, next to each other. When I click
I have three radio buttons with same name and different values.When I click the
In my application I have some link buttons there but when I right click
I have 2 radio buttons on a simple web page and If I click
I made 26 buttons, A-Z and when I click them the image of the

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.