最初はすべてが正しく表示されていましたが、スクロールするとラグが発生するだけでしArrayAdapter
た。を使用して解決策を見つけたので、最終的にListViewをスムーズにスクロールできますが、アイテムが混同されるという欠点があります。ListView
ListView
ViewHolder
ListView
どうすれば修正できますか?
私のgetView()
方法は次のArrayAdapter
とおりです。
public class VideoLocationAdapter extends ArrayAdapter<VideoLocationDB> {
public ImageLoader imageLoader;
ImageLoader loader = null;
public VideoLocationAdapter(Context context, int resource,
VideoLocationDB[] videoLocationDBs) {
super(context, resource, videoLocationDBs);
loader = new ImageLoader(context);
}
private LayoutInflater layoutInflator;
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
FeedViewHolder feedViewHolder;
if (convertView == null) {
convertView = LocationsListActivity.this.getLayoutInflater()
.inflate(R.layout.listitems, null, true);
feedViewHolder = new FeedViewHolder();
feedViewHolder.titleView = (TextView) convertView.findViewById(R.id.txt_title);
feedViewHolder.descView = (TextView) convertView.findViewById(R.id.txt_list_desc);
feedViewHolder.more = (TextView) convertView.findViewById(R.id.txt_more);
feedViewHolder.distanceView = (TextView) convertView.findViewById(R.id.txt_distance);
feedViewHolder.v = (ImageView) convertView.findViewById(R.id.image);
final VideoLocationDB vidLocation = videoLocationsDB[position];
// Image
String url = vidLocation.documentary_thumbnail_url;
String name = vidLocation.name;
feedViewHolder.v.setTag(url);
loader.DisplayImage(url, LocationsListActivity.this, feedViewHolder.v, name);
// Title
String title = vidLocation.name;
feedViewHolder.titleView.setText(title.toUpperCase());
Typeface fontRegular = Typeface.createFromAsset(getAssets(),
"miso.otf");
feedViewHolder.titleView.setTypeface(fontRegular);
// Description
String desc = vidLocation.text;
feedViewHolder.descView.setText(desc);
Typeface fontLight = Typeface.createFromAsset(getAssets(),
"miso-light.otf");
feedViewHolder.descView.setTypeface(fontLight);
// More
feedViewHolder.more.setText(getString(R.string.de_list_more));
feedViewHolder.more.setTypeface(fontLight);
// Distance
feedViewHolder.distanceView.setTypeface(fontRegular);
if (location != null) {
double lat = location.getLatitude();
double lng = location.getLongitude();
double lat2 = roundDown(vidLocation.latitude);
double lng2 = roundDown(vidLocation.longitude);
if (countDistance(lat, lng, lat2, lng2) >= 500) {
double kilometer = countDistance(lat, lng, lat2, lng2) / 1000;
int decimalPlaces = 1;
BigDecimal decimal = new BigDecimal(kilometer);
decimal = decimal.setScale(decimalPlaces,
BigDecimal.ROUND_HALF_UP);
double new_km = decimal.doubleValue();
feedViewHolder.distanceView.setText(new_km + " km");
} else {
int decimalPlaces = 1;
BigDecimal decimal = new BigDecimal(countDistance(lat, lng,
lat2, lng2));
decimal = decimal.setScale(decimalPlaces,
BigDecimal.ROUND_HALF_UP);
double meter = decimal.doubleValue();
feedViewHolder.distanceView.setText(meter + " m");
}
videoLocationAdapter.notifyDataSetChanged();
}
convertView.setTag(feedViewHolder);
} else
{
feedViewHolder = (FeedViewHolder) convertView.getTag();
}
return convertView;
}
static class FeedViewHolder{
TextView titleView;
TextView descView;
TextView more;
TextView distanceView;
ImageView v;
}