gpt4 book ai didi

java - fragment 不兼容的类型

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:56:13 25 4
gpt4 key购买 nike

Activity继承了ActoinBarActivity,它描述了侧边栏(NavigationDrawer),通过点击它的元素打开 fragment 。在其中一个 fragment 中有 listView,通过单击我要打开另一个 fragment 的项目(员工 - 员工列表 - 员工数据)。但是我是一个错误

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);
}
});

员工详细信息

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:

所有 fragment 必须import android.app.Fragment; 而不是android.support.v4.app.Fragment;

最佳答案

在您的类 EmployeeDetails 声明中,执行以下操作:

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

并使用import android.app.Fragment;

不使用import android.support.v4.app.Fragment;

关于java - fragment 不兼容的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24083788/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com