How can i connect more than 2 activities (Android App 35-36)

0 eleftheria batsou · April 14, 2015
Hello!

How can i create more than 2 activities and connect them.

I mean i want something like a simple menu, where in the "main anctivity" are let' s say 3 buttons: "a",  "b" and "c". 
How do i connect "main activity" with each "a",  "b" and "c"  activity,
and of cource "a", "b" and "c"  activity to "main activity" (something like return button)?!

Bucky did this for only 2 activities, and since i m new to android i dont understand how to solve my problem.
thanks!

Post a Reply

Replies

Oldest  Newest  Rating
0 Dol Lod · April 14, 2015
To clarify, you want buttons "a","b","c" to go to different activites, right?

You could add an OnClickListener for each button. This OnClickListener would react when one of the buttons is clicked and could use an intent  to go to the relevant activity. 


Intent theIntent = new Intent(getApplicationContext(),ImportTeams.class);

startActivity(theIntent);

The code above would allow you to switch between 2 activities. 


public void addListener()
{
listener=(new OnClickListener()
{

@Override
public void onClick(View view) 
{
switch(view.getId())
{
case R.id.selectAllRestaurantsButton:
allRestaurantsSelector(true);
break;
case R.id.deselectAllRestaurantsButton:
allRestaurantsSelector(false);
break;
case R.id.deleteSelectedRestaurantsButton:
deleteSelectedRestaurants();
break;
case R.id.exportSelectedRestaurantsButton:
exportSelectedRestaurants();
break;
case R.id.importRestaurantsButton:
importRestaurants();
break;
}

}
});
}

This code shows to use an OnClickListener with a case by case basis. The methods used are ones that simply change to a different activity that I made for simplicity. 

I hope this is what you you were looking for. 
0 Nicholas Eason · April 14, 2015
Intent i = new Intent(Context, WhateverClassYouWant.class);
startActivity(i);

Put that in an onClickListener of a button :P
  • 1

Java / Android Development

107,307 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator