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

相关推荐
2501_915106321 分钟前
苹果软件加固与 iOS App 混淆完整指南,IPA 文件加密、无源码混淆与代码保护实战
android·ios·小程序·https·uni-app·iphone·webview
2501_915921439 分钟前
iOS 26 崩溃日志解析,新版系统下崩溃获取与诊断策略
android·ios·小程序·uni-app·cocoa·iphone·策略模式
齊家治國平天下2 小时前
Android 14 Input 事件派发机制深度剖析
android·input·hal
2501_916013743 小时前
iOS 推送开发完整指南,APNs 配置、证书申请、远程推送实现与上架调试经验分享
android·ios·小程序·https·uni-app·iphone·webview
李艺为5 小时前
非预置应用使用platform签名并且添加了android.uid.system无法adb安装解决方法
android·adb
李宥小哥7 小时前
C#基础11-常用类
android·java·c#
Jerry12 小时前
Compose 中的绘制功能简介
android
我科绝伦(Huanhuan Zhou)13 小时前
【脚本升级】银河麒麟V10一键安装MySQL9.3.0
android·adb
消失的旧时光-194313 小时前
Android回退按钮处理方法总结
android·开发语言·kotlin