2

Im passing the selection of a list view through the intent using Extra but it is not picking it up.

The Log at the bottom of the below code shows that it is pulling the right name through to this class file, either cous cous, pasta, cake etc - but it will not show the logs in the if statements nor load the content views.

Any ideas?

public class RecipePage extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        String recipeName = (String) getIntent().getStringExtra("RecipeName");
        if(recipeName == "Cous Cous"){
            setContentView(R.layout.activity_couscous);
            Log.d("Joe", "1");
        }
        if(recipeName == "Rice"){
            setContentView(R.layout.activity_rice);
            Log.d("Joe", "2");
        }
        if(recipeName == "Burgers"){
            setContentView(R.layout.activity_burgers);
            Log.d("Joe", "3");
        }
        if(recipeName == "Pasta"){
            setContentView(R.layout.activity_pasta);
            Log.d("Joe", "4");
        }
        if(recipeName == "Chicken"){
            setContentView(R.layout.activity_chicken);
            Log.d("Joe", "5");
        }
        if(recipeName == "Cake"){
            setContentView(R.layout.activity_cake);
            Log.d("Joe", "6");
        }
        if(recipeName == "Roast"){
            setContentView(R.layout.activity_roast);
            Log.d("Joe", "7");
        }
        if(recipeName == "Lasagne"){
            setContentView(R.layout.activity_lasagne);
            Log.d("Joe", "8");
        }

        Log.d("Joe", "Recipe =" + recipeName);

    }
}
ThatBlairGuy
  • 2,426
  • 1
  • 19
  • 33
Joe Cory
  • 45
  • 5

1 Answers1

1

For comparing strings you should use equals() method.

Zigac
  • 1,551
  • 1
  • 16
  • 27