在ViewHolder模式中将ViewHolder设置为静态对性能至关重要吗?

Eug*_*ene 13 performance android listview

ViewHolder模式中将ViewHolder设置为静态对性能至关重要吗?

ViewHolder对象将每个组件视图存储在Layout的标记字段中,因此您可以立即访问它们而无需重复查找它们.首先,您需要创建一个类来保存您的确切视图集.例如:

static class ViewHolder {
  TextView text;
  TextView timestamp;
  ImageView icon;
  ProgressBar progress;
  int position;
}
Run Code Online (Sandbox Code Playgroud)

Jin*_*n35 8

它对于性能并不重要,它与使用有关.如果ViewHolderclass不是静态的 - 你必须提供父类的实例:

No enclosing instance of type Type is accessible. 
Must qualify the allocation with an enclosing instance of type Type 
(e.g. x.new A() where x is an instance of Type).
Run Code Online (Sandbox Code Playgroud)

  • 如果ViewHolder类在适配器类本身内部使用怎么办?那么你不必提供父类的实例...... (10认同)
  • 是的,你没有. (4认同)