private static class ContactAdapter extends BaseAdapter{

             private LayoutInflater mInflater;

             public ContactAdapter(Context context){

                    mInflater = LayoutInflater.from(context);

             }

             public int getCount() {

                    return mLength;

             }

             public Object getItem(int position) {

                    return position;

             }

             public long getItemId(int position) {

                    return position;

             }

             public View getView(int position, View convertView, ViewGroup parent) {

                    ViewHolder holder;

                   

                    if(convertView == null){

                          convertView = mInflater.inflate(R.layout.list_item_icon_text, null);

                           holder = new ViewHolder();

                           holder.name = (TextView)convertView.findViewById(R.id.contactName);

                           holder.number = (TextView)convertView.findViewById(R.id.contactNumber);

                           convertView.setTag(holder);

                    } else {

                           holder = (ViewHolder)convertView.getTag();

                    }

                    holder.name.setText(nameList.get(position));

                    holder.number.setText(numberList.get(position));

                    return convertView;

             }

             static class ViewHolder {

                     TextView name;

                     TextView number;

             }

       }




계속 쓰던것 보다 소스가 간단해 보이는 느낌이다. 하는일은 똑같다.



http://dodo4989.tistory.com/184



저작자 표시 비영리 변경 금지
신고
Posted by DoDo4989

댓글을 달아 주세요