Notice
Recent Posts
Recent Comments
Link
관리 메뉴

설.현.아빠

HolderPattern 좀더 간단히 구현된거. 본문

안드로이드/List

HolderPattern 좀더 간단히 구현된거.

설.현.아빠 2011. 5. 31. 10:34




 

       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



Comments