@@ -26,6 +26,10 @@ public class LogTableAdapter extends BaseAdapter {
2626 private List <LogRow > rows ;
2727 private static final String TAG = "DLT-Viewer" ;
2828
29+ private static class ViewHolder {
30+ private TextView [] column = new TextView [LogRow .ROW_COUNT ];
31+ }
32+
2933 public LogTableAdapter (Activity activity , List <LogRow > rows ) {
3034 super ();
3135 this .activity = activity ;
@@ -69,60 +73,60 @@ public long getItemId(int position) {
6973 @ Override
7074 public View getView (int position , View convertView , ViewGroup parent ) {
7175
76+ int i ;
77+ LogRow logRow = (LogRow )getItem (position );
78+
79+ ViewHolder viewHolder ;
7280 if (convertView == null ) {
81+ viewHolder = new ViewHolder ();
7382 LayoutInflater inflater = activity .getLayoutInflater ();
7483 convertView = inflater .inflate (R .layout .log_row , null );
84+
85+ viewHolder .column [LogRow .ROW_INDEX ] = (TextView ) convertView .findViewById (R .id .log_index );
86+ viewHolder .column [LogRow .ROW_TIMESTAMP ] = (TextView ) convertView .findViewById (R .id .log_timestamp );
87+ viewHolder .column [LogRow .ROW_ECUID ] = (TextView ) convertView .findViewById (R .id .log_ecuid );
88+ viewHolder .column [LogRow .ROW_APID ] = (TextView ) convertView .findViewById (R .id .log_apid );
89+ viewHolder .column [LogRow .ROW_CTID ] = (TextView ) convertView .findViewById (R .id .log_ctid );
90+ viewHolder .column [LogRow .ROW_SUBTYPE ] = (TextView ) convertView .findViewById (R .id .log_subtype );
91+ viewHolder .column [LogRow .ROW_PAYLOAD ] = (TextView ) convertView .findViewById (R .id .log_payload );
92+
93+ convertView .setTag (viewHolder );
94+ }
95+ else {
96+ viewHolder = (ViewHolder ) convertView .getTag ();
7597 }
76- TextView col0 = (TextView ) convertView .findViewById (R .id .log_index );
77- TextView col1 = (TextView ) convertView .findViewById (R .id .log_timestamp );
78- TextView col2 = (TextView ) convertView .findViewById (R .id .log_ecuid );
79- TextView col3 = (TextView ) convertView .findViewById (R .id .log_apid );
80- TextView col4 = (TextView ) convertView .findViewById (R .id .log_ctid );
81- TextView col5 = (TextView ) convertView .findViewById (R .id .log_subtype );
82- TextView col6 = (TextView ) convertView .findViewById (R .id .log_payload );
8398
8499 String timestamp = rows .get (position ).getColumn (LogRow .ROW_TIMESTAMP );
85100 String subtype = rows .get (position ).getColumn (LogRow .ROW_SUBTYPE );
86101
87102 int len = timestamp .length ();
88103 String new_timestamp = timestamp .substring (0 , len -4 ) + "." + timestamp .substring (len -4 , len );
89104 // Log.i(TAG, timestamp+" vs "+new_timestamp);
90- col0 .setText (rows .get (position ).getColumn (LogRow .ROW_INDEX ));
91- col1 .setText (new_timestamp );
92- col2 .setText (rows .get (position ).getColumn (LogRow .ROW_ECUID ));
93- col3 .setText (rows .get (position ).getColumn (LogRow .ROW_APID ));
94- col4 .setText (rows .get (position ).getColumn (LogRow .ROW_CTID ));
95- col5 .setText (subtype );
96- col6 .setText (rows .get (position ).getColumn (LogRow .ROW_PAYLOAD ));
105+
106+ viewHolder .column [LogRow .ROW_INDEX ].setText (rows .get (position ).getColumn (LogRow .ROW_INDEX ));
107+ viewHolder .column [LogRow .ROW_TIMESTAMP ].setText (new_timestamp );
108+ viewHolder .column [LogRow .ROW_ECUID ].setText (rows .get (position ).getColumn (LogRow .ROW_ECUID ));
109+ viewHolder .column [LogRow .ROW_APID ].setText (rows .get (position ).getColumn (LogRow .ROW_APID ));
110+ viewHolder .column [LogRow .ROW_CTID ].setText (rows .get (position ).getColumn (LogRow .ROW_CTID ));
111+ viewHolder .column [LogRow .ROW_SUBTYPE ].setText (subtype );
112+ viewHolder .column [LogRow .ROW_PAYLOAD ].setText (rows .get (position ).getColumn (LogRow .ROW_PAYLOAD ));
97113
98114 if (subtype .equals ("error" ) || subtype .equals ("fatal" )) {
99- col0 .setBackgroundResource (R .drawable .border_red );
100- col1 .setBackgroundResource (R .drawable .border_red );
101- col2 .setBackgroundResource (R .drawable .border_red );
102- col3 .setBackgroundResource (R .drawable .border_red );
103- col4 .setBackgroundResource (R .drawable .border_red );
104- col5 .setBackgroundResource (R .drawable .border_red );
105- col6 .setBackgroundResource (R .drawable .border_red );
115+ for (i =0 ;i <LogRow .ROW_COUNT ;i ++) {
116+ viewHolder .column [i ].setBackgroundResource (R .drawable .border_red );
117+ }
106118 }
107119 else if (subtype .equals ("warn" )) {
108- col0 .setBackgroundResource (R .drawable .border_yellow );
109- col1 .setBackgroundResource (R .drawable .border_yellow );
110- col2 .setBackgroundResource (R .drawable .border_yellow );
111- col3 .setBackgroundResource (R .drawable .border_yellow );
112- col4 .setBackgroundResource (R .drawable .border_yellow );
113- col5 .setBackgroundResource (R .drawable .border_yellow );
114- col6 .setBackgroundResource (R .drawable .border_yellow );
120+ for (i =0 ;i <LogRow .ROW_COUNT ;i ++) {
121+ viewHolder .column [i ].setBackgroundResource (R .drawable .border_yellow );
122+ }
115123 }
116124 else {
117- col0 .setBackgroundResource (R .drawable .border );
118- col1 .setBackgroundResource (R .drawable .border );
119- col2 .setBackgroundResource (R .drawable .border );
120- col3 .setBackgroundResource (R .drawable .border );
121- col4 .setBackgroundResource (R .drawable .border );
122- col5 .setBackgroundResource (R .drawable .border );
123- col6 .setBackgroundResource (R .drawable .border );
125+ for (i =0 ;i <LogRow .ROW_COUNT ;i ++) {
126+ viewHolder .column [i ].setBackgroundResource (R .drawable .border );
127+ }
124128 }
125129
126130 return convertView ;
127131 }
128- }
132+ }
0 commit comments