English 中文(简体)
在使用 custom调器和 SoftReference时的绩效咨询
原标题:Advise for performance when using custom Adapter and SoftReference in Android

我安装了一台调音器,以建立一个显示与地点有关的胎儿的方言箱(对话的每一条目都包括图像、显示地址的文字场和展示城市和国家的文本场)。 在适应器的收听(......)方法中,除了使用“观点”模式一外,还使用“软背”类来避免提及所形成的观点,以便在出现“外部”之前消除任何一种观点。 我的目标是建立一个更快、高效的海滩。 遵循我的习俗改编者守则:

public class LocationsAdapter extends ArrayAdapter<LocationInfo> {

Context context;
int layourResourceId;
List<LocationInfo> locations;

public LocationsAdapter(Context context, int layourResourceId,
        List<LocationInfo> locations) {
    super(context, layourResourceId, locations);

    this.context = context;
    this.layourResourceId = layourResourceId;
    this.locations = locations;
}

@Override
public View getView(int position, View row, ViewGroup parent) {

    LocationItemHolder holder = null;

    if (row != null && ((SoftReference<LocationItemHolder>) row.getTag()).get() != null) {

        holder = (LocationItemHolder) ((SoftReference<LocationItemHolder>) row.getTag()).get();

    } else {

        LayoutInflater inflater = ((Activity) context).getLayoutInflater();
        row = inflater.inflate(layourResourceId, parent, false);

        holder = new LocationItemHolder();
        holder.imgMarker = (ImageView) row.findViewById(R.id.imgMarker);
        holder.txtNameStreet = (TextView) row
                .findViewById(R.id.txtNameStreet);
        holder.txtRegion = (TextView) row.findViewById(R.id.txtRegion);

        row.setTag(new SoftReference<LocationItemHolder>(holder));
    }

    LocationInfo location = locations.get(position);
    holder.imgMarker.setImageResource(location.getMarkerId());
    holder.txtNameStreet.setText(location.getNameStreet());
    holder.txtRegion.setText(location.getRegion());

    return row;
}

class LocationItemHolder {
    ImageView imgMarker;
    TextView txtNameStreet;
    TextView txtRegion;
}
}

I am very interested in making things as efficient as possible. Although the code make what I want I m not sure if I m making good use SoftReference class. For example the sentence (LocationItemHolder) ((SoftReference ) row.getTag ()).get() I think it makes the cache ineffective because of the number of methods to be called to retrieve the desired object each time the method getView is invoked, also requires multiple castings. Can that sentence make inefficient the cache?. Is it advisable to use SoftReference in the context of an adapter in Android?

提前感谢您的答复:D

最佳回答

就我所知,在使用<代码>方面没有点。 页: 1 如果你重新正确征求回收意见(如你一样),你将只举几个例子:<代码>LocationItemHolder,这将永远相同(在同一改编者中)。 只有当适应者停止使用时,他们才会失效。

问题回答

如前所述,无需使用<代码>SoftReferences。

您的申请引起外部错误吗? 如果不是这样,就没有试图确定已经破碎的东西。

“我们应当忘记效率不高,大约占时间的97%:过早优化是一切邪恶的根源”。





相关问题
What to look for in performance analyzer in VS 2008

What to look for in performance analyzer in VS 2008 I am using VS Team system and got the performance wizard and reports going. What benchmarks/process do I use? There is a lot of stuff in the ...

SQL Table Size And Query Performance

We have a number of items coming in from a web service; each item containing an unknown number of properties. We are storing them in a database with the following Schema. Items - ItemID - ...

How to speed up Visual Studio 2008? Add more resources?

I m using Visual Studio 2008 (with the latest service pack) I also have ReSharper 4.5 installed. ReSharper Code analysis/ scan is turned off. OS: Windows 7 Enterprise Edition It takes me a long time ...

Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

热门标签