适配器类的android getview未调用为ArrayList.size()

时间:2014-04-02 09:30:25

标签: android android-adapter

你好,我已经在 getcount listCountry.size();中创建了一个adpter类,向我显示 实际大小为500 。但 getview 打电话给o * nly 11次*

public class ImageAdapter extends BaseAdapter {
        BitmapFactory.Options bmop;
        private ArrayList<String> listCountry;
        private Activity activity;

        public ImageAdapter(Activity activity, ArrayList<String> listCountry) {
            super();

            // this.listCountry = listCountry;
            this.listCountry = new ArrayList<String>();
            this.listCountry = listCountry;

            this.activity = activity;
            System.out.println("this is contry name " + this.listCountry);

        }

        @Override
        public int getCount() {
            System.out.println("len " + listCountry.size());// this shows 500
            return listCountry.size();
        }

        @Override
        public Object getItem(int position) {

            return listCountry.get(position);
        }

        @Override
        public long getItemId(int arg0) {
            // TODO Auto-generated method stub
            return arg0;
        }

        @Override
        public View getView(int arg0, View convertView, ViewGroup parent) {
            ViewHolder view;
            LayoutInflater inflator = activity.getLayoutInflater();
            if (convertView == null) {
                System.out.println(arg0+" this is from Adpter "+listCountry.get(arg0) );// this shows only first 11
                view = new ViewHolder();
                convertView = inflator.inflate(R.layout.item_grid_image, null);

                // Typeface typeface =
                // Typeface.createFromAsset(getAssets(),"fonts/DroidSerif.ttf");

                view.imgViewFlag = (ImageView) convertView
                        .findViewById(R.id.image);
                view.pb = (ProgressBar) convertView
                        .findViewById(R.id.progressBar1);

                // d.execute("http://java.sogeti.nl/JavaBlog/wp-content/uploads/2009/04/android_icon_256.png");

                // view.imgViewFlag.setBackgroundResource(R.drawable.view_default);
                convertView.setTag(view);

            } else {
                view = (ViewHolder) convertView.getTag();
            }
            try {
                // view.txtViewTitle.setText(listCountry.get(position));
                // view.imgViewFlag.setImageResource(listFlag.get(position));
                //DownloadImageTask d = new DownloadImageTask(view.imgViewFlag);
            //  d.execute(listCountry.get(arg0));

            } catch (Exception e) {
                System.out.println("this is error " + e.getMessage());
            }

            return convertView;
        }

    }

1 个答案:

答案 0 :(得分:0)

它只会使用适合您屏幕大小的项目填充列表,并且对您可见。如果你使用大图像,那么你可以感受到这种方法造成的滞后