listView的 Adapter优化

1, ListView 的Adapter 继承 BaseAdapter
2,通过getView()中的 holder 与convertView 进行布局的重用

   class TwosListAdapter extends BaseAdapter{

        private List<String> list ;

        public TwosListAdapter(List<String> list) {
            this.list = list;
        }

        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public Object getItem(int position) {
            return list.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup viewGroup) {
            ViewHolder holder ;
            if (convertView==null){
                holder = new ViewHolder();
                convertView = LayoutInflater.from(getActivity()).inflate(R.layout.twofragments_list_item_layout,null);
                holder.item_layout = (LinearLayout) convertView.findViewById(R.id.item_layout);

                holder.gcs_name =(TextView) convertView.findViewById(R.id.gcs_name);
                holder.gcs_renzheng =(TextView) convertView.findViewById(R.id.gcs_renzheng);
                holder.gcs_gonghao =(TextView) convertView.findViewById(R.id.gcs_gonghao);
                holder.gcs_gaojigongchengshi =(TextView) convertView.findViewById(R.id.gcs_gaojigongchengshi);
                holder.gcs_dazhuanxueli =(TextView) convertView.findViewById(R.id.gcs_dazhuanxueli);
                holder.gcs_jianjie =(TextView) convertView.findViewById(R.id.gcs_jianjie);

                holder.gcs_Progress = (ProgressBar) convertView.findViewById(R.id.gcs_Progress);

                convertView.setTag(holder);
            }else{
                holder = (ViewHolder) convertView.getTag();
            }

            holder.item_layout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent();
                    intent.setClass(getActivity(),GcsXiangqing.class);
                    startActivity(intent);
                }
            });



            return convertView;
        }

        class ViewHolder{

            LinearLayout item_layout ;
            TextView gcs_name ,
                    gcs_renzheng ,
                    gcs_gonghao,
                    gcs_gaojigongchengshi,
                    gcs_dazhuanxueli ,
                    gcs_jianjie;
            ProgressBar gcs_Progress ;
        }
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值