Android: Implementing ViewHolder

后端 未结 3 1724
灰色年华
灰色年华 2020-12-15 21:11

I am trying to implement ViewHolder in my Android app, but I keep getting that ViewHolder cannot be resolved to a type, without any suggestions for an import. Anyone know ho

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-15 21:41

    That's because a ViewHolder is not a class that is from the Android SDK, you make it yourself. Based on what I can find, a ViewHolder is an implementation that stores Views (per row in a ListView usually) for a larger area, so it is a sort of helper class and cache mechanism. This is one example I found on Android Developers of what a ViewHolder would contain.

    static class ViewHolder {
      TextView text;
      TextView timestamp;
      ImageView icon;
      ProgressBar progress;
      int position;
    }
    

    Then you can implement it in a ListAdapter or a similar class.

提交回复
热议问题