2012-03-21 9 views
0

私は何か愚かなことをしていると確信していますが、これは本当に混乱しています。Android:ListViewのセルが正しく描画されないようです

このコードのほとんどは、StackOverflowのいくつかの素晴らしい答えから取られています。

以下のコードでは、アラーム文字列の上に表示されるトラブルシューティング文字列を取得しますが、 セル定義はアラーム文字列を先頭に置きます。

マイセルが

<?xml version="1.0" encoding="utf-8"?>      
<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"        
    >               

    <TextView             
     android:id="@+id/ar_alarm_text"      
     android:layout_width="wrap_content"     
     android:layout_height="wrap_content"     
     android:text="@+strings/alarm_dummy" />    

    <TextView             
     android:id="@+id/ar_trouble_text"      
     android:layout_width="wrap_content"     
     android:layout_height="wrap_content"     
     android:text="@+strings/trouble_dummy" />    

</LinearLayout> 

alarm_list_row私はArrayAdapter

public class ComfortListAlarmArrayAdapter extends ArrayAdapter<StringPair> {   
    private final Context context;              
    private final ArrayList<StringPair> items;           

    //Constructors                  
    public ComfortListAlarmArrayAdapter(Context context, ArrayList<StringPair> 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();              
    }                     

}                      

から延長アダプタを使用していて、私のlogCatは

を示した場合、それはAlarmActivity

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);                    
     }                              
    }                              
}  

に使用されている

03-22 01:25:42.112: I/CommsController:setAlarm(26655): System Armed,Code 240 

the cell shows 
    ------------ 
    Code 240 
    System Armed 
    ------------ 

誰かが私が見落としていることを指摘できますか?

複雑なことは申し訳ありません - 通信スレッドなどから渡されるメッセージは残されていますが、ログメッセージに文字列が正しい場所に表示されるはずです。

答えて

0

LogCatがSystem Armedのコードを表示しているときにコードが表示されていて、次にSystem Armedと表示されていることが問題であると推測しています。それが問題であれば、enter code here alarm_list_rowレイアウトを見て、TextViewという名前が適切であることを確認する必要があります。

+0

確認済み - 私は何か愚かなことをしていました。 変数を切り替えてデータ(StringPair)を初期化していましたが、そのコードは表示されません。ログはコードの別の部分から来ています:( LogCatメッセージが一致していないことを再度確認しました... "Alaem View"対 "setAlarm" どうもありがとうございました。 –

関連する問題