How to use AppCompatActivity functions inside a Fragment? [duplicate]

1

I have a fragment and need within it some of the functions of AppCompatActivity, how to implement the two in the same class?

You're like this:

public class clientes extends Fragment {

I've tried:

public class clientes extends Fragment implementes AppCompatActivity{

Or vise versa.

If it is not possible to do, how do I do this check:

ConnectivityManager connMgr = (ConnectivityManager)
                getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();

        if (networkInfo != null && networkInfo.isConnected()) {

The getSystemService is red, and you can not use it in the fragment Also, I need to use the:

 @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    View view = 
  act.getLayoutInflater().inflate(R.layout.lista_curso_personalizada, 
  parent, false);

The getLayoutInflater () also turns red, shows that it can not be used in a

    
asked by anonymous 31.01.2018 / 21:13

1 answer

2

getSystemService is a Context method. Activity is Context , so you can use call directly when it is within Activity . Fragment is not a Context , so you need to get a Context object and call getSystemService . The easiest way is:

getActivity().getSystemService(Context.CONNECTIVITY_SERVICE).
    
31.01.2018 / 23:02