title: Android change layout depending on if statement
body: <p>Im trying to inflate a view depending on screen size so I can use different layouts</p>
  
  <p><strong>I have tried the following</strong></p>
  
  <pre><code>double screen_size = 8
  
  if screen_size &gt;= 10 {
      layoutInflator =(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      View row = layoutInflator.inflate(R.layout.mylist, parent, false);
  } 
  
  if screen_size &gt;= 5 &amp;&amp; screen_size  &lt;=9){
      layoutInflator =(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      View row = layoutInflator.inflate(R.layout.mylist2, parent, false);
  } 
  
  TextView textview1 = (TextView) row.findViewById(R.id.textView1);
  </code></pre>
  
  <p>I get an error on the <code>Textview</code> saying <code>row</code> cannot be resolved even tho the <code>if</code> statement is being run</p>
  
  <p><strong>If I change to</strong></p>
  
  <pre><code>double screen_size = 8
  
  if screen_size &gt;= 10 {
      layoutInflator =(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      View row = layoutInflator.inflate(R.layout.mylist2, parent, false);
  } 
  
  if screen_size &gt;= 5 &amp;&amp; screen_size  &lt;=9){
      layoutInflator =(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      View row = layoutInflator.inflate(R.layout.mylist2, parent, false);
      } 
  
  View row = layoutInflator.inflate(R.layout.mylist, parent, false);
  
  TextView textview1 = (TextView) row.findViewById(R.id.textView1);
  </code></pre>
  
  <p>it runs fine but always runs layout <code>mylist</code> instead of <code>mylist2</code></p>
  
  <p>Any ideas where im going wrong</p>
  
  <p>Any help appreciated</p>
  
  <p>Mark</p>