【发布时间】:2014-06-06 14:06:36
【问题描述】:
还有Activity继承ActoinBarActivity,它描述了侧边栏(NavigationDrawer),通过点击它的元素打开片段。在其中一个片段中有listView,通过单击我要打开另一个片段的项目(员工-员工列表-员工数据)。但我是个错误
不兼容的类型: 必需:Android.app.Fragment 找到: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);
}
}
答案是:
所有片段必须import android.app.Fragment; 而不是android.support.v4.app.Fragment;
【问题讨论】:
-
@CyberneticTwerkGuruOrc 这是我的代码
-
@CyberneticTwerkGuruOrc 如何解决:HomeFragment 必须扩展 Fragment 没有效果
-
你能告诉我们这门课
EmployeeDetails吗? -
@CyberneticTwerkGuruOrc 你可以看到
-
感谢您清楚地写出答案。也可以移到顶部。
标签: java android android-fragments