Cannot resolve getSystemService method in ListView adapter

后端 未结 8 1527
深忆病人
深忆病人 2021-01-25 00:23

I am working through John Horton\'s Android Programming for Beginners, and am currently attempting to create a note-taking app. Horton has just introduced ListVie

8条回答
  •  Happy的楠姐
    2021-01-25 00:41

    The best way to get a LayoutInflater is by calling getLayoutInflater() on an Activity. That way, the activity's theme is taken into account. If NoteAdapter is defined inside of an Activity, just call getLayoutInflater(). If NoteAdapter is defined in its own separate Java class file, pass in a LayoutInflater via the constructor.

    To more directly address your question, any View, like ListView, can call getContext() to get a Context. That is where getSystemService() is defined. So, replacing getSystemService() with viewGroup.getContext().getSystemService() would work.

提交回复
热议问题