BaseExpandableListAdapter getChildView update TextView per item
I have an expandable list view that I am populating with values from a
Track object that contains a list of Locations. It runs well. However my
TextView.setText is filling in each textView with the LAST value in the
list of Locations.
How can I fix this?
public View getChildView(int groupPosition, int childPosition, boolean
isLastChild, View convertView, ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater)
myContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView =
inflater.inflate(R.layout.list_child_item_layout, null);
for (Location loc :
trackList.get(groupPosition).getLocations()) {
//Log.i(MY_EXPANDABLELIST_ACTIVITY_TAG, "Location X: " +
loc.getLongitude());
TextView textLongitude = (TextView)
convertView.findViewById(R.id.textView_longitude);
textLongitude.setText("Longitude: " +
Double.toString(loc.getLongitude()));
TextView textLatitude = (TextView)
convertView.findViewById(R.id.textView_latitude);
textLatitude.setText("Latitude: " +
Double.toString(loc.getLatitude()));
TextView textAltitude = (TextView)
convertView.findViewById(R.id.textView_altitude);
textAltitude.setText("Altitude: " +
Double.toString(loc.getAltitude()));
TextView textSpeed = (TextView)
convertView.findViewById(R.id.textView_speed);
textSpeed.setText("Speed: " +
Float.toString(loc.getSpeed()));
TextView textAccuracy = (TextView)
convertView.findViewById(R.id.textView_accuracy);
textAccuracy.setText("Accuracy: " +
Float.toString(loc.getAccuracy()));
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy
HH:mm:ss", Locale.ENGLISH);
Date date = new Date(loc.getTime());
String formattedDate = format.format(date);
TextView textTime = (TextView)
convertView.findViewById(R.id.textView_time);
textTime.setText("Time: " + formattedDate);
}
}
return convertView;
}
The values are correct in LogCat.
No comments:
Post a Comment