要解决这个问题,你需要按照以下步骤进行操作:
public class CheckFragment extends Fragment {
// 在这里添加你的代码
}
private ArrayList items;
public CheckFragment(ArrayList items) {
this.items = items;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_check, container, false);
// 初始化列表视图
ListView listView = view.findViewById(R.id.listView);
ArrayAdapter itemsAdapter = new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, items);
listView.setAdapter(itemsAdapter);
return view;
}
ArrayList items = new ArrayList<>();
// 添加一些数据到items列表中
CheckFragment fragment = new CheckFragment(items);
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.add(R.id.fragment_container, fragment);
fragmentTransaction.commit();
通过按照以上步骤操作,你将能够成功创建并显示一个包含列表视图的Fragment。