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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:06:22+00:00 2026-05-28T06:06:22+00:00

Well I have a main Screen with 5 buttons. Each time a press a

  • 0

Well I have a main Screen with 5 buttons. Each time a press a button I want to go a new screen. So far I have other 5 classes (each for each screen) and 5 xmls. But Iam sure that there will be a better way beacuse this screen and the xmls are the same, and what I want to do is change some texts and some data I fetch from a database. I am sure that I can ony another class and only one xml and then pass the values that I want as arguments. (Imagine that in its final state my app must have 15 buttons, so I think it is too mych waste of space and unnecessary to have 15 .java files and 15 xml files that look the same and only some values of images and textviews change). My code for main activity is:

public class MyActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    main2Theme();}

private void main2Theme() {
    setContentView(R.layout.main_new);

    Button Button100 = (Button)findViewById(R.id.Button100);
Button113.setOnClickListener(new OnClickListener()
    {   
        public void onClick(View v)
        {
            Intent i = new Intent(this, OtherScreenName.class);
           startActivity(i);
        }
    }); //and so on for 15 buttons

My OtherScreenName.class is:

public class OtherScreenName extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Theme();
}

 @SuppressWarnings("null")
    private void Theme() {
        Log.d("SnowReportApp","Do first thing");
        setContentView(R.layout.otherscreenname); //THIS CHANGES IN EVERY CLASS DEPENDING ON THE ID OF THE BUTTON
        String result = "";
        InputStream is = null;
        StringBuilder sb=null;

        ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();//() before
        nameValuePairs.add(new BasicNameValuePair("ski_id","OtherScreenName"));
        TextView text1 = (TextView) findViewById(R.id.otherscreenname_1);
//THESE 2 CHANGE DEPERNDING ON THE BUTTON PRESSED
//perform action.....

//AND ALSO HERE I NEED THE ID OF THE BUTTON

 b1.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent i = new Intent(OtherScreenName.this,MyActivity.class);
                startActivity(i);

        }
        }); 

Can anyone suggest how to give arguments to my class and what it should be the type of them?

  • 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-28T06:06:23+00:00Added an answer on May 28, 2026 at 6:06 am

    If I understand your question correctly, you want to pass arguments to the activity. Normally it would be done through the class constructor, however, activities can’t have user defined constructors, only the default one; they can be instantiated only indirectly via intent creation. If you need to pass data between activities, do it by putting extras to bundles, for example:

    bundle.putInt("intName",intValue);
    

    then you can extract the data from bundle by

    int intValue = bundle.getInt("intName");
    

    Put extras before starting the activity:

    Intent i = new Intent(this, YourActivity.class);
    Bundle b = new Bundle();
    
    b.putInt("intName",intValue);
    i.putExtras(b);
    startActivity(i);
    

    and then read the extras in the onCreate method:

    public void onCreate(Bundle savedInstanceState)
    {
       super.onCreate(savedInstanceState);
    
       Bundle b = getIntent().getExtras();
       int intValue;
    
       if (b != null)
       {
          intValue= b.getInt("intName");
       }
    }
    

    The same way you can pass other data types as String boolean etc. If this is not sufficient and you need to pass some more complex data, then use Parcelable interface.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have several input and option elements on my page, each (well almost) have
In my app I have four tabs in the bottom of my main screen.
I am trying to create a screen with some dynamic controls, well radio buttons
I have an app which has a main activity that calls other activities on
well i have this messages table with sample values like these: msg_id recipient_id read
Well I have a videos website and a few of its tables are: tags
Well I have this MySQL stored procedure that I wrote and if I run
Well i have 2 css includes <link href=Styles/layout.css rel=stylesheet type=text/css /> <link href=Styles/ATJournal.css rel=stylesheet
Well I have a series of sps that are running a data warehousing solution
Well i have a gridview where i have defined the columns on my own

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.