Garf1eld
Garf1eld

Reputation: 608

Fragments Incompatible types

There Activity inherits ActoinBarActivity, it describes the sidebar (NavigationDrawer), by clicking on its elements open fragments. In one of the fragments have listView, by clicking on the item which I want to open another fragment ( staff- a list of employees - employee data). But I is an error

Incompatible types: Required: Android.app.Fragment Found:com.abc.app.EmployeeDetails

public class MyEmployeeFragment extends Fragment {
//some code
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
    userList = new ArrayList<User>();
    sAdapter = new CustomAdapter(getActivity(),userList);
    View rootView = inflater.inflate(R.layout.my_employe, container, false);
    ListView lv = (ListView)rootView.findViewById(R.id.list);
    lv.setAdapter(sAdapter);

    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
        int position, long id) {
            Fragment f = new EmployeeDetails(); // ERROR
            FragmentManager fragmentManager = getFragmentManager();
            FragmentTransaction ft = fragmentManager.beginTransaction();
            ft.replace(R.id.content_frame, f);
            ft.commit();
            Log.i("TAG", "itemClick: position = " + position + ", id = "
            + id);
        }
    });

EmployeeDetails

public class EmployeeDetails extends Fragment {



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_employee_details, container, false);
    }


}

Answer is:

All fragments must import android.app.Fragment; not android.support.v4.app.Fragment;

Upvotes: 8

Views: 12695

Answers (2)

user6427267
user6427267

Reputation: 76

Use import android.support.v4.app.Fragment; Its Working me.

Upvotes: -4

GWN
GWN

Reputation: 609

In your class EmployeeDetails declaration, do this:

public class EmployeeDetails extends Fragment {
......

And use import android.app.Fragment;

not use import android.support.v4.app.Fragment;

Upvotes: 20

Related Questions