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;
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With