【发布时间】:2025-12-09 15:15:03
【问题描述】:
我明白了,每次调用 view.findViewById(R.id.title);是非常昂贵的操作。我如何通过存储这些 int 值来优化它。在 List Adapter 中使用的优化方式是什么?
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;
final DataObject dataObject = getItem(position);
if (view == null) {
// No view created yet
LayoutInflater layoutInflater = LayoutInflater.from(getContext());
view = layoutInflater.inflate(layoutResourceId, parent, false);
}
if (view != null) {
TextView title = (TextView) view.findViewById(R.id.title);
TextView price = (TextView) view.findViewById(R.id.price);
ImageView img = (ImageView) view.findViewById(R.id.profile_pic);
RatingBar overallRating = (RatingBar) view.findViewById(R.id.overall_rating);
【问题讨论】:
-
ViewHolder 模式
标签: android android-listview android-arrayadapter listadapter