Cannot resolve getSystemService method in ListView adapter

后端 未结 8 1361
深忆病人
深忆病人 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:46

    mContext is Context which you pass to Custom Adapter

      public boolean CheckInternet() {
            ConnectivityManager connectivityManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
            if (connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState() == NetworkInfo.State.CONNECTED ||
                    connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState() == NetworkInfo.State.CONNECTED) {
                //we are connected to a network
                return true;
            }
            return false;
        }//end of check internet
    
    0 讨论(0)
  • 2021-01-25 00:49

    Use view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.listitem, viewGroup,false);

    0 讨论(0)
提交回复
热议问题