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

The Archive Base Latest Questions

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

I have 2 activities – Say Activity A and B. My main activity(A) has

  • 0

I have 2 activities – Say Activity A and B.
My main activity(A) has 2 buttons. I start another activity when Button 1 is clicked. The second activity(B) creates a listview which uses a string array to populate custom list items.

Now when Button 2 in Activity A is clicked, I want to populate the list view using the same code in Activity B but use a different string array. How do I do that? I don’t want to create another activity just to replace the string arryay for the ListView.

/*ACTIVITY A /

 public class mainmenu extends Activity {

 @Override
 public void onCreate(Bundle savedInstanceState) {
 requestWindowFeature(Window.FEATURE_NO_TITLE);
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);


 Button button1 = (Button) findViewById(R.id.Button01);
 button.setOnClickListener(new View.OnClickListener() {
 public void onClick(View v) {
       // Perform action on click

 Intent i = new Intent(getApplication(), ActivityB.class);
 startActivity(i);
   });


 Button button2 = (Button) findViewById(R.id.Button02);
 button1.setOnClickListener(new View.OnClickListener() {
 public void onClick(View v) {
  Intent i = new Intent(getApplication(), ActivityB.class);
       startActivity(i);


   }
  });

/* ACTIVITY B****

public class anotheractivity extends ListActivity {




public void onCreate(Bundle icicle) {
super.onCreate(icicle);

    String[] names = getResources().getStringArray(R.array.heading_name);
    String[] descr = getResources().getStringArray(R.array.heading_desc);
    this.setListAdapter(new myArrayAdapter(this, names, descr));
    ListView lv = getListView();

    Resources res = getResources();

    Drawable sm = res.getDrawable(R.drawable.mydivider);


    lv.setDivider(sm);
    lv.setDividerHeight(1);
}
  • 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-25T06:20:17+00:00Added an answer on May 25, 2026 at 6:20 am

    You can pass in data to your Activity B using putExtra. Please see this question for a good example. In your Activity B you can get this data, and populate your list according to what was passed in.

    For activity A:

    Intent i = new Intent(ActivityA.this, ActivityB.class);
    i.putExtra("arrayToUse", 1);
    startActivity(i);
    

    For activity B you would do something like this in the onCreate:

    Bundle extras = icicle.getExtras();
    int whichArrayToUse = extras.getInt("arrayToUse");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my application I have several activities, the main screen has 4 buttons that
I have two activities one displaying map view and another listview, the main objective
I have two activities, one is main and I have another activity called Test
I have three activities 1 is the main activity 2 is some other activity
I have two activities; Home is my first activity and Settings is my second
I have two activities. Home activity contain a list view with two buttons named
I have 2 activities. In activity A when pressing a button sends you to
I have two activities, say Activity A and Activity B . Activity A is
I have two activities. In first I come to the second activity from first
I have two Sharepoint lists: - Assignments - Activities The activities list has a

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.