title: Android : ListView cell seems to draw incorrectly
body: <p>I am sure that I am doing something stupid but I'm really confused over this….</p>
  
  <p>Most of this code is taken from some great answers on StackOverflow….</p>
  
  <p>In the code below - I get the trouble string shown on top of the alarm string but the 
  cell definition puts the alarm string on top.</p>
  
  <p>My cell is alarm_list_row</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;                       
  &lt;LinearLayout                                                 
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"                       
      android:layout_height="wrap_content"                      
      android:padding="10dp"                                    
      android:orientation="vertical"                            
      &gt;                                                         
  
      &lt;TextView                                                 
          android:id="@+id/ar_alarm_text"                       
          android:layout_width="wrap_content"                   
          android:layout_height="wrap_content"                  
          android:text="@+strings/alarm_dummy" /&gt;               
  
      &lt;TextView                                                 
          android:id="@+id/ar_trouble_text"                     
          android:layout_width="wrap_content"                   
          android:layout_height="wrap_content"                  
          android:text="@+strings/trouble_dummy" /&gt;             
  
  &lt;/LinearLayout&gt;  
  </code></pre>
  
  <p>I am using an adaptor extended from ArrayAdapter</p>
  
  <pre><code>public class ComfortListAlarmArrayAdapter extends ArrayAdapter&lt;StringPair&gt; {         
      private final Context context;                                                     
      private final ArrayList&lt;StringPair&gt; items;                                         
  
      //Constructors                                                                     
      public ComfortListAlarmArrayAdapter(Context context, ArrayList&lt;StringPair&gt; items) {
          super(context, R.layout.comfort_alarm_cell);                                     
          this.context = context;                                                          
          this.items = items;                                                              
      }                                                                                  
  
      private class AlarmViewHolder {                                                    
          public TextView alarm;                                                           
          public TextView trouble;                                                         
      }                                                                                  
  
      private AlarmViewHolder alarmHolder;                                               
  
  
      @Override                                                                          
      public View getView(int position, View convertView, ViewGroup parent) {            
          View rowView=convertView;                                                        
  
          if(rowView == null){                                                             
              LayoutInflater inflater = (LayoutInflater) context                             
                      .getSystemService(Context.LAYOUT_INFLATER_SERVICE);                        
              rowView = inflater.inflate(R.layout.alarm_list_row, parent, false);            
              alarmHolder = new AlarmViewHolder();                                           
              alarmHolder.alarm = (TextView) rowView.findViewById(R.id.ar_alarm_text);       
              alarmHolder.trouble = (TextView) rowView.findViewById(R.id.ar_trouble_text);   
              rowView.setTag(alarmHolder);                                                   
  
              //          LayoutInflater inflater = context.getLayoutInflater();                 
  //          rowView = inflater.inflate(R.layout.comfort_list_row, null, true);           
          } else alarmHolder = (AlarmViewHolder) rowView.getTag();                         
  
  
          StringPair alarm = items.get(position);                                          
          if (alarm != null) {                                                             
              alarmHolder.alarm.setText(alarm.getAlarm());                                   
              if (alarm.getTrouble().trim().length() == 0) {                                 
                  alarmHolder.trouble.setText(" ");                                            
                  //alarmHolder.trouble.setVisibility(android.view.View.INVISIBLE);            
              } else {                                                                       
                  alarmHolder.trouble.setText(alarm.getTrouble());                             
                  //alarmHolder.trouble.setVisibility(android.view.View.VISIBLE);              
              }                                                                              
              Log.v("Alarm View", alarm.getAlarm()+"/"+alarm.getTrouble());                  
          }                                                                                
          rowView.setBackgroundColor(Color.BLACK);                                         
          return rowView;                                                                  
      }                                                                                  
  
  
      /* (non-Javadoc)                                                                   
       * @see android.widget.ArrayAdapter#getCount()                                     
       */                                                                                
      @Override                                                                          
      public int getCount() {                                                            
          return items.size();                                                             
          //return super.getCount();                                                       
      }                                                                                  
  
  }                                                                                    
  </code></pre>
  
  <p>and it is being used in an AlarmActivity</p>
  
  <pre><code>public class AlarmActivity extends Activity implements MessageThumper{                                                   
  
      private ComfortListAlarmArrayAdapter alarmListAdapter;                                                                 
      private final int AA_NEW_MESSAGE = 1;                                                                                  
  
      CommunicationsController getComms()                                                                                    
      {                                                                                                                      
          ComfortApp main = (ComfortApp) getApplicationContext();                                                              
          return main.Comms;                                                                                                   
      }                                                                                                                      
  
      /** Called when the activity is first created. */                                                                      
      @Override                                                                                                              
      public void onCreate(Bundle savedInstanceState) {                                                                      
          super.onCreate(savedInstanceState);                                                                                  
          setContentView(R.layout.alarms);                                                                                 
          final ListView lv_1  = (ListView) findViewById(R.id.alarm_list);                                                     
  
          alarmListAdapter = new ComfortListAlarmArrayAdapter(AlarmActivity.this, getComms().am_alarmStuff);                   
          lv_1.setAdapter(alarmListAdapter);                                                                                   
      }                                                                                                                      
  
      Handler alarmUpdateHandler = new Handler(){                                                                            
  
              @SuppressWarnings("unchecked")                                                                                     
              @Override                                                                                                          
              public void handleMessage(Message msg) {                                                                           
                  if(msg.what == AA_NEW_MESSAGE){                                                                                  
                      //update all adapters                                                                                          
                      ((ComfortListAlarmArrayAdapter)((ListView) findViewById(R.id.alarm_list)).getAdapter()).notifyDataSetChanged();
                  }                                                                                                                
                  super.handleMessage(msg);                                                                                        
              }                                                                                                                                                                                      
      };                                                                                                                                                                                                                                                 
  
      public void passMessage(String msg, String p1, String p2) {                                                            
          if (msg.equals("NEW_ALARM"))                                                                                         
          {                                                                                                                    
              Message M = new Message();                                                                                         
              M.what = AA_NEW_MESSAGE;                                                                                           
              this.alarmUpdateHandler.sendMessage(M);                                                                            
          }                                                                                                                    
      }                                                                                                                      
  }      
  </code></pre>
  
  <p>if my logCat shows</p>
  
  <pre><code>03-22 01:25:42.112: I/CommsController:setAlarm(26655): System Armed,Code 240
  
  the cell shows
      ------------
      Code 240
      System Armed
      ------------
  </code></pre>
  
  <p>Can somebody point what I am overlooking?</p>
  
  <p>I'm sorry for the extra complexity - the message passing from the comms thread etc. is left in but he Log message should show that the strings are in the correct places….                                                                                             </p>