2

最初はすべてが正しく表示されていましたが、スクロールするとラグが発生するだけでしArrayAdapterた。を使用して解決策を見つけたので、最終的にListViewをスムーズにスクロールできますが、アイテムが混同されるという欠点があります。ListViewListViewViewHolderListView

どうすれば修正できますか?

私の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;
    }
4

1 に答える 1

3

if if (convertView == null) {} および else の後にテキストを外側/外側に設定しています

if (convertView == null) { //ビューを作成する }else { //convertView からビューを取得する }

ここでビューにテキストを設定します

見る

http://android.amberfog.com/?p=296

@Override
        public View getView(int position, View convertView, ViewGroup parent) {
            System.out.println("getView " + position + " " + convertView);
            ViewHolder holder = null;
            if (convertView == null) {
                convertView = mInflater.inflate(R.layout.item1, null);
                holder = new ViewHolder();
                holder.textView = (TextView)convertView.findViewById(R.id.text);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder)convertView.getTag();
            }

         holder.textView.setText(mData.get(position));//<========== see it .....
            return convertView;
        }

    }

このコードを if/else の後に置きます

 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();
                } 
于 2012-05-30T13:27:51.283 に答える