Android fragment的写

c 复制代码
package com.zs.test_.fragment;
import java.util.HashMap;

public class MyFragment extends Fragment {
    TextView tv_id, tv_share_my, tv_gold;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_my, container, false);
        SharedPreferencesUtils sharedPreferencesUtils = SharedPreferencesUtils.getInstance(getActivity());
        about_my = view.findViewById(R.id.about_my);
        return view;
    }

    @Override
    public void onDetach() {
        super.onDetach();

        EventBus.unregister(this);
    }
}

1.继承于fragment

extends Fragment

2.将 XML 布局文件 (R.layout.fragment_no_fold_tab)解析为对应的 View 层次结构。

View view = inflater.inflate(R.layout.fragment_my, container, false);、

相关推荐
alexhilton9 小时前
模块化Jetpack Compose架构
android·kotlin·android jetpack
厮年断弦11 小时前
AI 辅助开发实录:一周做完一个 Android 本地音乐播放器,这些坑替你踩了
android
hai_android11 小时前
InputStage 责任链核心执行流程
android·android studio·android jetpack
mmsx14 小时前
Android 测绘计算工程化:七四参数、高程拟合与单位系统
android·kotlin
我是场16 小时前
我的NPI项目之-Touch的EE特性
android·arm开发
天空之城--16 小时前
Android一周动态:AI编程、Compose与车载生态新信号
android·flutter
恋猫de小郭17 小时前
Dart 4.0 要彻底移除 dart:mirrors,Augmentations 应该要来了
android·前端·flutter
Carson带你学Android18 小时前
Gemini 4 Argon 发布:对 Android 开发者意味着什么?
android·ai编程
事圆则缓19 小时前
Kotlin Flow、StateFlow、SharedFlow 全解析:冷流、热流与 Android 状态管理
android·kotlin·php
应用市场19 小时前
把旧 Pixel 变成相册备份中转站(上):Mac 到安卓的照片传输工具设计——流式上传、sha256 校验、adb forward 与 Bonjour
android·macos·adb·kotlin·swift