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

相关推荐
alexhilton7 小时前
使用FunctionGemma进行设备端函数调用
android·kotlin·android jetpack
冬奇Lab10 小时前
InputManagerService:输入事件分发与ANR机制
android·源码阅读
张小潇13 小时前
AOSP15 Input专题InputManager源码分析
android·操作系统
RdoZam15 小时前
Android-封装基类Activity\Fragment,从0到1记录
android·kotlin
奥陌陌21 小时前
android 打印函数调用堆栈
android
用户9851200358321 小时前
Compose Navigation 3 深度解析(二):基础用法
android·android jetpack
恋猫de小郭21 小时前
Android 官方正式官宣 AI 支持 AppFunctions ,Android 官方 MCP 和系统级 OpenClaw 雏形
android·前端·flutter
黄林晴1 天前
Android 17 Beta 2,隐私这把锁又拧紧了
android
Kapaseker1 天前
研究表明,开发者对Kotlin集合的了解不到 20%
android·kotlin
bqliang1 天前
Compose 媒体查询 (Media Query API) 🖱️👇🕹️
android·android jetpack