Android 导航抽屉和碎片
我有我的导航抽屉,它很好用。现在我创建了片段:Android 导航抽屉和碎片,android,android-fragments,Android,Android Fragments,我有我的导航抽屉,它很好用。现在我创建了片段: public class LabourFragment extends Fragment { private ListView listViewLabour; private String[] resourcesList; public LabourFragment() { // Required empty public constructor } @Override publ
public class LabourFragment extends Fragment {
private ListView listViewLabour;
private String[] resourcesList;
public LabourFragment() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
//set adapter
//TODO: change later to proper resource pull from server
//have to use getActivity() as this is fragment and findViewById works from activity only
ListView listView = (ListView) getActivity().findViewById(R.id.drawerList);
listView.setAdapter(new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, resourcesList));
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_labour, container, false);
}
}
现在我从主活动调用片段:
public void selectItem(int position) {
listView.setItemChecked(position, true);
setTitle(getResources().getTextArray(R.array.drawerMenuList)[position]);
FragmentManager fragmentManager = getFragmentManager();
//TODO: open proper acvtivity
switch (position){ //positions reflects menu in drawer
case 0:
LabourFragment fragment = new LabourFragment();
fragmentManager.beginTransaction()
.replace(R.id.mainContentFragment, fragment)
.commit();
break;
}
并获取错误消息:
错误:100,25错误:找不到适用于replaceint,LabourFragment的方法
方法FragmentTransaction.replaceint,Fragment不适用
无法通过方法调用转换将实际参数LabourFragment转换为片段
试图将LabourFragment抛成碎片,但运气不佳。
我做错了什么?
谢谢。您的活动扩展了什么?您的碎片导入了什么?您似乎正在使用支持库中的碎片和原始源代码中的碎片。谢谢。现在很明显。