I have a menu at the beginning of my application which allows the user to choose a specific type of diet, I want to save this as a string to use in another class which finds nearby restaurants,cafes,etc.
For example, if the user chooses the "Vegan" card, then I want to be able to use "Vegan" in other classes, but if it's "Kosher" I want to use the string "kosher" in other classes.
I tried creating a DietChoice
class to set/get the diet but that doesn't work because I can't create a HomeMenu
object in my MapsActivity
class.
How can I make it so that when the user clicks the Vegan card, I can make it so that I can use a string "Vegan" in my MapsActivity
class?
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.CardView;
import android.view.View;
public class HomeMenu extends AppCompatActivity implements View.OnClickListener {
private CardView veganMenu,halalMenu,vegeterianMenu,kosherMenu;
private DietChoice diet;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_menu);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
public void onClick(View v) {
Intent intent = new Intent(this,Home.class)
switch (v.getId()) {
case R.id.vegan_menu:
intent.putExtra("STRING_I_NEED", "vegan");
startActivity(intent);
break;
case R.id.vegetarian_menu:
intent.putExtra("STRING_I_NEED", "vegetarian");
startActivity(intent);
break;
case R.id.halal_menu:
intent.putExtra("STRING_I_NEED", "halal");
startActivity(intent);
break;
case R.id.kosher_menu:
intent.putExtra("STRING_I_NEED", "kosher");
startActivity(intent);
break;
}