0
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import static android.icu.lang.UCharacter.GraphemeClusterBreak.T;
import static com.example.noah.app1.R.id.lstview;

public class Tab2 extends Fragment {

    ListView lstview;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.tab2, container, false);

        lstview = (ListView) rootView.findViewById(R.id.lstview);
        Tab2_list_view adapter = new Tab2_list_view(Tab2.this);

        lstview.setAdapter(adapter);

        return rootView;
    }
}

Here I get an error saying: Error:(27, 57) error: incompatible types: Tab2 cannot be converted to Context

Tab2 is my MainActivity and Tab2_list_view has my code on for a ListView.

How can I fix this?

Ele
  • 33,468
  • 7
  • 37
  • 75
user3519870
  • 91
  • 2
  • 10

1 Answers1

1

Instead of :

Tab2.this

you need to use the Activity Context. Use:

getActivity()

instead

rafsanahmad007
  • 23,683
  • 6
  • 47
  • 62