android开发教程之使用listview显示qq联系人列表

2019-12-10 20:10:06于海丽

            ctSign=(TextView)convertView.findViewById(to[2]);

        }

    }    
    class ImageListener implements OnClickListener{

        private int position;

        public ImageListener(int position){
            this.position=position;
        }                          //构造函数没有返回值

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            String str=list.get(position).get(from[1]).toString();
            Toast.makeText(context,str+" is Clicked" , Toast.LENGTH_LONG).show();

        }

    }
    @Override
    public View getView(int position, View convertView, ViewGroup arg2) {
        // TODO Auto-generated method stub

        /**
         * 首先判断是不是第一次创建Item,若是,则创建convertView实例和ViewHolder对象,并通过fandViewById()方法
         * 获得每一行中所有空间的实例放在ViewHolder对象中,然后对convertView设置标签
         */
        ViewHolder viewHolder=null;

        //注意convertView不是随意创建的,需要有LayoutInflater,根据list_item布局文件创建
        if(convertView==null){
            LayoutInflater inflater=LayoutInflater.from(context);
            convertView=inflater.inflate(resources,null);    //这里的null是一个ViewGroup形参,基本用不上
            viewHolder=new ViewHolder(convertView);
            convertView.setTag(viewHolder);