Efficiency Optimization of multiple itemviews in ExpandListView; expandlistview

Source: Internet
Author: User

Efficiency Optimization of multiple itemviews in ExpandListView; expandlistview

A problem recently encountered in the project is that multiple itemviews and groupviews in the ExpandListView need to be initialized each time. This efficiency can only be improved! The idea is so proceed!

Previously we used the following Optimization for a single itemView in a Listview!

FitListViewHolder viewHolder; if (convertView = null) {convertView = LayoutInflater. from (context ). inflate (R. layout. fitlistitem, null); viewHolder = new FitListViewHolder (convertView, context); convertView. setTag (viewHolder);} else {viewHolder = (FitListViewHolder) convertView. getTag ();} // load the data viewHolder. setContent (yiLists. get (position ));

Most people should handle it like this, and so do I!

If multiple responsibilities are directly extended as follows:

 if (symptomResultType == SymptomResultType.SYMPTOM_TYPE_COMMON_METHOD) {            CommonMethodViewHolder viewHolder;            if(convertView == null || !(convertView.getTag() instanceof CommonMethodViewHolder)) {                convertView = LayoutInflater.from(mContext).inflate(R.layout.list_item_common_method, null);                viewHolder = new CommonMethodViewHolder(convertView, mContext);                convertView.setTag(viewHolder);            }else{                viewHolder = (CommonMethodViewHolder) convertView.getTag();            }            Object[] userMethods = userSymptomResultModel.userMethodDatas.toArray();            viewHolder.setMethodContent((UserMethod) userMethods[childPosition]);            return convertView;        } else if (symptomResultType == SymptomResultType.SYMPTOM_TYPE_HABIT) {            UserHabitViewHolder viewHolder;            if(convertView == null || !(convertView.getTag() instanceof UserHabitViewHolder)) {                convertView = LayoutInflater.from(mContext).inflate(R.layout.list_item_habit, null);                viewHolder = new UserHabitViewHolder(convertView, mContext);                convertView.setTag(viewHolder);            }else{                viewHolder = (UserHabitViewHolder) convertView.getTag();            }            Object[] userHabits = userSymptomResultModel.userHabitDatas.toArray();            viewHolder.setHabitContent((UserHabit) userHabits[childPosition]);            return convertView;        }

The central idea is to obtain the gettag based on whether the contentView is null or not, and check whether the View is required by the current item. If not, create the View again. It's okay to retrieve it based on the tag!

Debug executes the desired result!


You are welcome to make a brick!



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.