我突然在我的列表视图中得到重复的元素。当我对列表项进行 onClick 操作时,一切都恢复正常。我还检查了我的适配器,我没有在 ArrayList 中添加多个项目。这里可能有什么问题。
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null || convertView.getTag() == null) {
convertView = inflater.inflate(R.layout.bookingresponse_row, null);
final CabbieViewHolder viewHolder = new CabbieViewHolder();
viewHolder.call = (ImageView) convertView.findViewById(R.id.callCab);
viewHolder.call.setOnClickListener(this);
viewHolder.driverName = (TextView) convertView.findViewById(R.id.driverName);
//SIMILAR CODE FOR MORE DATA ITEMs
convertView.setTag(viewHolder);
}
// Setting all values in listview
String temp = latestAcceptedCabbieName.get(position);
((CabbieViewHolder) (convertView.getTag())).driverName.setText(temp);
((CabbieViewHolder) (convertView.getTag())).inDetailsDriverName.setText(temp);
//SIMIAR CODE for other data items
// Smoothen out the list
new AsyncTask<Object, Void, Float>() {
CabbieViewHolder cabbieViewHolder;
@Override
protected Float doInBackground(Object... params) {
float cabDistanceFromCustomer = -1.0f;
cabbieViewHolder = (CabbieViewHolder) params[0];
if (cabbieViewHolder.distanceFromCustomer == -1.0f) {
int position = (int) ((Integer) params[1]).intValue();
cabbieViewHolder.distanceFromCustomer = cabDistanceFromCustomer = God
.getGeoDistance(Double.valueOf(latestAcceptedCabbieSourceGPSX
.get(position)), Double
.valueOf(latestAcceptedCabbieSourceGPSY.get(position)),
Double.valueOf(customerSourceLat / 1E6), Double
.valueOf(customerSourceLng / 1E6));
} else
cabDistanceFromCustomer = cabbieViewHolder.distanceFromCustomer;
return cabDistanceFromCustomer;
}
@Override
protected void onPostExecute(Float result) {
super.onPostExecute(result);
if (customerSourceLat != 0 && customerSourceLng != 0) {
String temp;
if (result != 0) {
temp = "Current Location @ Approx "
+ String.format("%.1f", result / 1000) + " km";
cabbieViewHolder.cabDistance.setText(temp);
cabbieViewHolder.inDetailsCabDistance.setText(temp);
} else {
cabbieViewHolder.cabDistance.setVisibility(View.GONE);
cabbieViewHolder.inDetailsCabDistance.setVisibility(View.GONE);
}
} else {
cabbieViewHolder.cabDistance.setVisibility(View.GONE);
cabbieViewHolder.inDetailsCabDistance.setVisibility(View.GONE);
}
}
}.execute((CabbieViewHolder) convertView.getTag(), new Integer(position));
return convertView;
}