So I’m trying to create an activity that passes some values into another activity and then, depending on those values, chooses one of several different layouts.
I know that the values are passed through fine, but it won’t display the layout (or any layout, it just stays on the previous screen). My code is:
public class ContactDisplay extends GetContact {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
String nameChosen = extras.getString("nameSpinner");
String addressChosen = extras.getString("addressSpinner");
if((nameChosen == "Michael") && (addressChosen == "Michaels Address")){
setContentView(R.layout.contact1_layout);
}
}
}
I’ve only set it up to with one of the layouts so far, but it should work if Michael and Michaels Address are chosen. Does anyone have any idea where I’m going wrong?
Use this code instead:
In Java you want to use the equals() function when comparing strings not the == operator.