在HTC One OS 4.3上的notifyDataSetChanged()之后的列表视图性能非常慢

时间:2014-09-25 06:36:58

标签: android android-4.3-jelly-bean

我有一个列表视图和onItemClick我必须刷新列表,更改行标题的文本颜色。它在除HTC One之外的所有其他设备上都能正常工作。以下是代码段:

// Part of Framgent which extends BaseFragment which extends RoboSherlockFragment
list.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1,int position, long arg3) {
                Log.e("Cuurent Time setOnItemClickListener", ""+ new SimpleDateFormat("HH:mm:ss.SSS").format(new Date()));
                onItemClicked(position,adapter);
            }

        });

private void onItemClicked(int position, ArrayAdapter<FollowUpAction> adapter){
    MyApplication.logger.log(Level.INFO,"Type: "+ adapter.getItem(position).getType() + "--");
    FollowUpAction selectedItem = adapter.getItem(position);
    if () 
    {
    }
    else if () 
    {
    } else {
       // this condition gets called
        if(adapter instanceof FollowUpListActionAdapter){
            ((FollowUpListActionAdapter) adapter).onClickOperation(position);;
        }else{
            ((FollowUpActionAdapter) adapter).onClickOperation(position);;
        }
    }
}

public void onClickOperation(int position) {
    int index = isAlreadSelected(position);
    if (index == -1) {
        selected.add(data.get(position));
        DataHolder.getInstance().updateSelectedFollowUpActionList(data.get(position));
    } else {
        selected.remove(index);
        DataHolder.getInstance().removeFromFollowoupActionList(data.get(position));
    }
    notifyDataSetChanged();
}

public View getView(int position, View convertView, ViewGroup parent) {
    Log.e("Cuurent Time getView for positon", position+"::::"+ new SimpleDateFormat("HH:mm:ss.SSS").format(new Date()));
    ViewHolderItem viewHolder;
    View row = convertView;
    if (row == null) 
    {
        row = inflater.inflate(R.layout.topics_item_layout, parent, false);
        viewHolder = new ViewHolderItem();
        viewHolder.textView = (TextView) row.findViewById(R.id.topicItemTextView);
        viewHolder.imageView = (ImageView) row.findViewById(R.id.topicsItemImageView);
        row.setTag(viewHolder);
    } else 
    {
        viewHolder = (ViewHolderItem) row.getTag();
    }
    viewHolder.textView.setText(data.get(position).getLabel().toString());
    if (data.get(position).getChildren() != null&& data.get(position).getChildren().size() > 0) 
    {
        viewHolder.imageView.setVisibility(View.VISIBLE);
        if (isAlreadSelected(position) != -1) 
        {
            viewHolder.textView.setTextColor(context.getResources().getColor(R.color.appGreenColor));
            viewHolder.imageView.setImageResource(R.drawable.green_arrow);
        } else 
        {
            viewHolder.textView.setTextColor(context.getResources().getColor(R.color.appGrayColor));
            viewHolder.imageView.setImageResource(R.drawable.light_gray_select_field_arrow_rotated);
        }
    } else 
    {
        viewHolder.imageView.setVisibility(View.GONE);
        if (isAlreadSelected(position) != -1) 
        {
            viewHolder.textView.setTextColor(context.getResources().getColor(R.color.appGreenColor));
        } else 
        {
            viewHolder.textView.setTextColor(context.getResources().getColor(R.color.appGrayColor));
        }
    }
    return row;
}

以上是本案例中使用的代码。如果我将此片段更改为单独的Activity,它将开始正常工作。

请在这方面帮助我。

0 个答案:

没有答案