Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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;

like image 913
Garf1eld Avatar asked Jun 06 '14 14:06

Garf1eld


1 Answers

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;

like image 100
Lucas Santos Avatar answered Nov 17 '22 20:11

Lucas Santos