0

Maybe it is difficult to understand the title but let me explain. So I am working on an sports application. The main idea - I will parse official website which contains match schedule, results, stats, team info etc. Now I am working on the UI before I make functions for parsing and storage of data. It should look something like this: ActivityTeams will contain the following buttons: Team 1 Team 2 Team 3 ...

For every team make a new activity but inside of these activities I will need the same buttons - Team info, stats, results etc. So it will be appropriate to make these activities only for once and just somehow load different data on them. If the path will be Teams > Team 1> Stats the data on display will be different than if it will be Teams > Team 2> Stats. How can I do this? I understand that I can open the same activity from every other activity I would like to but how to make the function for displaying different data in the same activity depending on the path? Any tips, suggestions? Thanks!

anthropophagus
  • 643
  • 1
  • 6
  • 7
  • Possible duplicate of [How do I pass data between activities on Android?](http://stackoverflow.com/questions/2091465/how-do-i-pass-data-between-activities-on-android) – Jack Ryan Oct 11 '16 at 16:38

2 Answers2

0

You can achieve this using intents, so go read the android doc.

Android Intents - Tutorial

Jerry Okafor
  • 3,710
  • 3
  • 17
  • 26
0

You can use Intents in Android to switch from one Activity to other and pass some identifier(like Team name or Team id).

Call a Activity on button click and pass the identifier as an Extra in Intent.

Access the Intent Extra you passed in your Activity(which would start on click), and manipulate it with switch

Something like this

//In TeamActivity
    Intent i = new Intent(getBaseContext(), TeamActivity.class);
    i.putExtra("team_id", 01);
    startActivity(i);

//In clicked Activity
    int teamId = getIntent().getIntExtra("team_id",00)

    switch(teamId){
      case 01:

          //Make changes for when Team with id 01 is clicked

      break;
      case 02:

          //Make changes for when Team with id 02 is clicked

      break;
    }                    
Siddhesh Dighe
  • 2,894
  • 3
  • 16
  • 16