Android : How can I display a view for an activity based on a value passed through an intent from another activity?
<p>I have two activities. Activity1.java and Activity2.java I have 5 buttons in the view of Activity1. Each button must open Activity2.java but must display different view for different buttons. </p>

<p>Activity1.java - activity1_view.xml</p>

<p>Activity2.java - activity2_view1.xml  for Button 1<br/>
Activity2.java - activity2_view2.xml  for Button 2<br/>
Activity2.java - activity2_view3.xml  for Button 3<br/>
Activity2.java - activity2_view4.xml  for Button 4<br/>
Activity2.java - activity2_view5.xml  for Button 5<br/></p>

<p>I have posted my code. It is not working</p>

<p>Can anyone tell where I am wrong?</p>

<p>Activity1.java</p>

<pre><code>private View.OnClickListener sButton1Listener = new View.OnClickListener(){
    public void onClick(View v){
         Intent i = new Intent(Activity1.this, Activity2.class);
         i.putExtra("Button", "1");
         startActivity(i);
    }
};
</code></pre>

<p>Activity2. java </p>

<pre><code>@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    Bundle extras = getIntent().getExtras();
    if(extras !=null){
        String value = extras.getString("Button");
        if(value == "1"){
            setContentView(R.layout.activity2_view1);
        }
        else if(value == "2"){
            setContentView(R.layout.activity2_view2);
        }
        else if(value == "3"){
            setContentView(R.layout.activity2_view3);
        }
        else if(value == "4"){
            setContentView(R.layout.activity2_view5);
        }
        else if(value == "5"){
            setContentView(R.layout.activity2_view5);
        }
   }
}
</code></pre>

<p>Solved:
As told by joni, i corrected if(value == "1") to if(value.equals("1") and the code is working. I just compared String objects just like integers. That was my problem.</p>
