我有一个可扩展的列表视图,我使用来自包含位置列表的 Track 对象的值填充该列表视图。它运行良好。但是,我的 TextView.setText 正在使用位置列表中的 LAST 值填充每个 textView。
我怎样才能解决这个问题?
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;
}
LogCat 中的值是正确的。