给我提供一份viewpager2+Fragment的java demo源码
时间: 2024-01-15 13:03:12 浏览: 69
viewpager+fragment的使用Demo
非常感谢您对ChitGPT的使用和信任!以下是一个ViewPager2 Fragment的Java示例源码:
```
public class MyFragment extends Fragment {
private static final String ARG_PARAM1 = "param1";
private String mParam1;
public MyFragment() {
// Required empty public constructor
}
public static MyFragment newInstance(String param1) {
MyFragment fragment = new MyFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
}
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_my, container, false);
TextView textView = view.findViewById(R.id.text_view);
textView.setText(mParam1);
return view;
}
}
```
希望这个示例代码对您有帮助。如果您还有其他问题或建议,请随时提出,我会尽力为您提供帮助。
阅读全文