Cannot resolve getSystemService method in ListView adapter

后端 未结 8 1376
深忆病人
深忆病人 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条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-25 00:40

    Try

    public class NoteAdapter extends BaseAdapter {
    
        Context mContext = null;
    
        public NoteAdapter(Context context){
           mContext = context;
        }
    
    
        @Override
        public View getView(int whichItem, View view, ViewGroup viewGroup){
    
            // check if view has been inflated already
            if (view == null){
                LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); // ERROR HERE
    
                view = inflater.inflate(R.layout.listitem, viewGroup, false);
    
            }
    
            return view;
        }
    
    }
    

提交回复
热议问题