使用supportFragmentManager管理多个fragment切换
android studio创建的项目就没有一个简单点的框架,生成的代码都是繁琐而复杂,并且不实用。
国内的页面一般都是TAB页面的比较多,老外更喜欢侧边菜单。
如果我们使用一个activity来创建程序,来用占位符管理多个fragment切换,这里水一篇最简单直接的做法。
源码:
https://download.csdn.net/download/robinfoxnan/89485371?spm=1001.2014.3001.5503
预览:https://img-blog.csdnimg.cn/direct/e38ca75c7a694b049366ef05da984ef6.jpeg
## **1. Java**实现
在 Android 开发中,使用 FragmentManager 来管理多个 Fragment 页面是一个常见的做法。可以通过以下步骤在主页面的占位符上替换多个 Fragment:
-
创建主 Activity 布局:在你的主 Activity 布局文件中,创建一个
FrameLayout作为占位符,用于显示Fragment。<!-- activity_main.xml --> <FrameLayoutandroid:id="@+id/fragment_container"android:layout_width="match_parent"android:layout_height="match_parent" /> -
创建 Fragments:创建多个
Fragment,每个Fragment都有自己的布局和逻辑。// ExampleFragment.java public class ExampleFragment extends Fragment {@Nullable@Overridepublic View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {return inflater.inflate(R.layout.fragment_example, container, false);} }<!-- fragment_example.xml --> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><!-- Fragment content goes here --><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Example Fragment" /> </LinearLayout> -
在主 Activity 中管理 Fragments:在你的主 Activity 中使用
FragmentManager来替换占位符中的Fragment。// MainActivity.java public class MainActivity extends AppCompatActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);// 默认加载的 Fragmentif (savedInstanceState == null) {getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new ExampleFragment()).commit();}}// 用于切换 Fragment 的方法public void switchFragment(Fragment fragment) {getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, fragment).addToBackStack(null).commit();} } -
切换 Fragment:在主 Activity 中调用
switchFragment方法来切换不同的Fragment。// 切换到另一个 Fragment switchFragment(new AnotherFragment());
通过这种方式,你可以在主页面的占位符上动态替换多个 Fragment 页面。你可以根据需要在不同的事件(如按钮点击)中调用 switchFragment 方法来切换不同的 Fragment。
2.kotlin实现
2.1 添加基础切换流程
下面是用 Kotlin 实现上述功能的步骤:
-
创建主 Activity 布局:在你的主 Activity 布局文件中,创建一个
FrameLayout作为占位符,用于显示Fragment。<!-- activity_main.xml --> <FrameLayoutandroid:id="@+id/fragment_container"android:layout_width="match_parent"android:layout_height="match_parent" /> -
创建 Fragments:创建多个
Fragment,每个Fragment都有自己的布局和逻辑。// ExampleFragment.kt class ExampleFragment : Fragment() {override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,savedInstanceState: Bundle?): View? {// Inflate the layout for this fragmentreturn inflater.inflate(R.layout.fragment_example, container, false)} }<!-- fragment_example.xml --> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><!-- Fragment content goes here --><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Example Fragment" /> </LinearLayout> -
在主 Activity 中管理 Fragments:在你的主 Activity 中使用
FragmentManager来替换占位符中的Fragment。// MainActivity.kt class MainActivity : AppCompatActivity() {override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)// 默认加载的 Fragmentif (savedInstanceState == null) {supportFragmentManager.beginTransaction().replace(R.id.fragment_container, ExampleFragment()).commit()}}// 用于切换 Fragment 的方法fun switchFragment(fragment: Fragment) {supportFragmentManager.beginTransaction().replace(R.id.fragment_container, fragment).addToBackStack(null).commit()} } -
切换 Fragment:在主 Activity 中调用
switchFragment方法来切换不同的Fragment。// 切换到另一个 Fragment switchFragment(AnotherFragment())
通过这种方式,可以在主页面的占位符上动态替换多个 Fragment 页面。你可以根据需要在不同的事件(如按钮点击)中调用 switchFragment 方法来切换不同的 Fragment。
2.2 页面中获取主界面
在 AnotherFragment 中获取 MainActivity 的实例并调用 switchFragment 方法,你可以使用 Kotlin 的 activity 属性,它返回当前 Fragment 所附着的 Activity 实例。你需要确保类型转换安全,避免强制转换引起的异常。
下面是一个示例:
-
创建
AnotherFragment:在AnotherFragment中编写逻辑来获取MainActivity实例并调用switchFragment方法。// AnotherFragment.kt class AnotherFragment : Fragment() {override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,savedInstanceState: Bundle?): View? {// Inflate the layout for this fragmentreturn inflater.inflate(R.layout.fragment_another, container, false)}override fun onViewCreated(view: View, savedInstanceState: Bundle?) {super.onViewCreated(view, savedInstanceState)// 假设你有一个按钮来触发 Fragment 切换val button: Button = view.findViewById(R.id.switch_fragment_button)button.setOnClickListener {(activity as? MainActivity)?.switchFragment(ExampleFragment())}} }<!-- fragment_another.xml --> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><!-- Fragment content goes here --><Buttonandroid:id="@+id/switch_fragment_button"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Switch to Example Fragment" /> </LinearLayout> -
更新
MainActivity:确保MainActivity里有一个方法switchFragment可以被调用。// MainActivity.kt class MainActivity : AppCompatActivity() {override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)// 默认加载的 Fragmentif (savedInstanceState == null) {supportFragmentManager.beginTransaction().replace(R.id.fragment_container, ExampleFragment()).commit()}}// 用于切换 Fragment 的方法fun switchFragment(fragment: Fragment) {supportFragmentManager.beginTransaction().replace(R.id.fragment_container, fragment).addToBackStack(null).commit()} }
通过这种方式,你可以在 AnotherFragment 中获取 MainActivity 的实例并调用 switchFragment 方法来切换 Fragment。这利用了 Kotlin 的安全类型转换 (as?) 来确保在类型转换失败时返回 null,而不是引发异常。
2.3 复用fragment
每次调用 switchFragment 方法时,都会创建一个新的 Fragment 实例并替换当前的 Fragment。如果你希望在切换 Fragment 时复用已有的 Fragment 实例,而不是每次都创建一个新的,可以在 MainActivity 中维护这些 Fragment 的实例。
下面是一个示例,展示如何在 MainActivity 中维护 Fragment 实例,并在切换时复用这些实例:
-
在
MainActivity中维护Fragment实例:// MainActivity.kt class MainActivity : AppCompatActivity() {private lateinit var exampleFragment: ExampleFragmentprivate lateinit var anotherFragment: AnotherFragmentoverride fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)if (savedInstanceState == null) {// 初始化 Fragment 实例exampleFragment = ExampleFragment()anotherFragment = AnotherFragment()// 默认加载的 FragmentsupportFragmentManager.beginTransaction().replace(R.id.fragment_container, exampleFragment).commit()} else {// 恢复已存在的 Fragment 实例exampleFragment = supportFragmentManager.findFragmentByTag("ExampleFragment") as ExampleFragmentanotherFragment = supportFragmentManager.findFragmentByTag("AnotherFragment") as AnotherFragment}}// 用于切换 Fragment 的方法fun switchFragment(fragment: Fragment, tag: String) {supportFragmentManager.beginTransaction().replace(R.id.fragment_container, fragment, tag).addToBackStack(null).commit()} } -
在
AnotherFragment中调用switchFragment方法:// AnotherFragment.kt class AnotherFragment : Fragment() {override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,savedInstanceState: Bundle?): View? {// Inflate the layout for this fragmentreturn inflater.inflate(R.layout.fragment_another, container, false)}override fun onViewCreated(view: View, savedInstanceState: Bundle?) {super.onViewCreated(view, savedInstanceState)// 假设你有一个按钮来触发 Fragment 切换val button: Button = view.findViewById(R.id.switch_fragment_button)button.setOnClickListener {(activity as? MainActivity)?.switchFragment((activity as MainActivity).exampleFragment, "ExampleFragment")}} }
通过这种方式,你可以在 MainActivity 中维护 Fragment 的实例,并在切换时复用这些实例,而不是每次都创建一个新的 Fragment。在调用 switchFragment 方法时,通过传递 Fragment 实例和对应的标签(tag)来替换当前的 Fragment。
2.4 map来管理多个fragment
可以使用一个 Map 来管理多个 Fragment 实例。这可以使得管理 Fragment 的实例更加灵活和高效。你可以在 MainActivity 中使用 Map 来存储 Fragment 实例,并在需要切换 Fragment 时从 Map 中获取相应的实例。
以下是一个示例,展示如何使用 Map 来管理多个 Fragment 实例:
-
在
MainActivity中定义一个Map来存储Fragment实例:// MainActivity.kt class MainActivity : AppCompatActivity() {private val fragmentMap = mutableMapOf<String, Fragment>()override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)if (savedInstanceState == null) {// 初始化 Fragment 实例并存储到 Map 中fragmentMap["ExampleFragment"] = ExampleFragment()fragmentMap["AnotherFragment"] = AnotherFragment()// 默认加载的 FragmentswitchFragment("ExampleFragment")}}// 用于切换 Fragment 的方法fun switchFragment(tag: String) {val fragment = fragmentMap[tag]fragment?.let {supportFragmentManager.beginTransaction().replace(R.id.fragment_container, it, tag).addToBackStack(null).commit()}} } -
在
AnotherFragment中调用switchFragment方法:// AnotherFragment.kt class AnotherFragment : Fragment() {override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,savedInstanceState: Bundle?): View? {// Inflate the layout for this fragmentreturn inflater.inflate(R.layout.fragment_another, container, false)}override fun onViewCreated(view: View, savedInstanceState: Bundle?) {super.onViewCreated(view, savedInstanceState)// 假设你有一个按钮来触发 Fragment 切换val button: Button = view.findViewById(R.id.switch_fragment_button)button.setOnClickListener {(activity as? MainActivity)?.switchFragment("ExampleFragment")}} } -
在
ExampleFragment中调用switchFragment方法(类似AnotherFragment):// ExampleFragment.kt class ExampleFragment : Fragment() {override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,savedInstanceState: Bundle?): View? {// Inflate the layout for this fragmentreturn inflater.inflate(R.layout.fragment_example, container, false)}override fun onViewCreated(view: View, savedInstanceState: Bundle?) {super.onViewCreated(view, savedInstanceState)// 假设你有一个按钮来触发 Fragment 切换val button: Button = view.findViewById(R.id.switch_fragment_button)button.setOnClickListener {(activity as? MainActivity)?.switchFragment("AnotherFragment")}} }
通过这种方式,你可以使用一个 Map 来管理多个 Fragment 实例,并在需要时通过标签(tag)来切换 Fragment。这使得 Fragment 的管理更加灵活和高效。
2.5 使用库模块中的界面
当然可以!在 Android 项目中,你可以导入其他模块或库,并在你的应用中使用它们定义的 Fragment。以下是一个示例,展示如何导入一个模块并使用该模块中定义的 Fragment。
假设你有一个名为 mylibrary 的模块,其中定义了一个 CustomFragment。
-
在你的项目中导入模块:
首先,确保你的项目的
settings.gradle文件中包含了该模块:include ':app', ':mylibrary' -
添加模块依赖:
在你的应用模块的
build.gradle文件中添加对mylibrary模块的依赖:dependencies {implementation project(':mylibrary')// 其他依赖项 } -
在你的模块中定义
Fragment:在
mylibrary模块中定义一个CustomFragment:// mylibrary/src/main/java/com/example/mylibrary/CustomFragment.kt package com.example.mylibraryimport android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragmentclass CustomFragment : Fragment() {override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,savedInstanceState: Bundle?): View? {// Inflate the layout for this fragmentreturn inflater.inflate(R.layout.fragment_custom, container, false)} }<!-- mylibrary/src/main/res/layout/fragment_custom.xml --> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><!-- Fragment content goes here --><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Custom Fragment" /> </LinearLayout> -
在主应用中使用
CustomFragment:现在你可以在你的主应用中使用
mylibrary模块中定义的CustomFragment。// MainActivity.kt import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment import com.example.mylibrary.CustomFragmentclass MainActivity : AppCompatActivity() {private val fragmentMap = mutableMapOf<String, Fragment>()override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)if (savedInstanceState == null) {// 初始化 Fragment 实例并存储到 Map 中fragmentMap["ExampleFragment"] = ExampleFragment()fragmentMap["AnotherFragment"] = AnotherFragment()fragmentMap["CustomFragment"] = CustomFragment()// 默认加载的 FragmentswitchFragment("ExampleFragment")}}// 用于切换 Fragment 的方法fun switchFragment(tag: String) {val fragment = fragmentMap[tag]fragment?.let {supportFragmentManager.beginTransaction().replace(R.id.fragment_container, it, tag).addToBackStack(null).commit()}} } -
在
AnotherFragment中调用switchFragment方法:// AnotherFragment.kt class AnotherFragment : Fragment() {override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,savedInstanceState: Bundle?): View? {// Inflate the layout for this fragmentreturn inflater.inflate(R.layout.fragment_another, container, false)}override fun onViewCreated(view: View, savedInstanceState: Bundle?) {super.onViewCreated(view, savedInstanceState)// 假设你有一个按钮来触发 Fragment 切换val button: Button = view.findViewById(R.id.switch_fragment_button)button.setOnClickListener {(activity as? MainActivity)?.switchFragment("CustomFragment")}} }
通过这种方式,你可以导入一个模块,并在主应用中使用该模块中定义的 Fragment。这使得代码更加模块化和可复用。
相关文章:
使用supportFragmentManager管理多个fragment切换
android studio创建的项目就没有一个简单点的框架,生成的代码都是繁琐而复杂,并且不实用。 国内的页面一般都是TAB页面的比较多,老外更喜欢侧边菜单。 如果我们使用一个activity来创建程序,来用占位符管理多个fragment切换&…...
开源模型应用落地-FastAPI-助力模型交互-WebSocket篇(六)
一、前言 使用 FastAPI 可以帮助我们更简单高效地部署 AI 交互业务。FastAPI 提供了快速构建 API 的能力,开发者可以轻松地定义模型需要的输入和输出格式,并编写好相应的业务逻辑。 FastAPI 的异步高性能架构,可以有效支持大量并发的预测请求,为用户提供流畅的交互体验。此外,F…...
独立开发者系列(17)——MYSQL的常见异常整理
虽然安装MYSQL到本地很简单,但是数据库报错还是经常出现,这个时候,需要我们进行逐步检查与修复。作为我们最常用的开发软件,无论切换php/go/python/node/java,数据库的身影都少不了,对于我们储存数据而言&a…...
【ajax实战02】数据管理网站—验证码登录
一:数据提交(提交手机验证码) 核心思路整理 利用form-serialize插件,收集对象形式的表单数据后,一并提交给服务器。后得到返回值,进一步操作 基地址: axios.defaults.baseURL http://geek.…...
人工智能在反无人机中的应用介绍
人工智能技术在无人机的发展中扮演着至关重要的角色,这一作用在反无人机技术领域同样显著。随着无人机技术的发展,飞行器具备了微小尺寸、高速机动性,以及可能采用的隐蔽或低空飞行轨迹等特性。这些特性使得传统的人工监视和控制手段面临着重…...
【力扣 - 每日一题】3115. 质数的最大距离(一次遍历、头尾遍历、空间换时间、埃式筛、欧拉筛、打表)Golang实现
原题链接 题目描述 给你一个整数数组 nums。 返回两个(不一定不同的)质数在 nums 中 下标 的 最大距离。 示例 1: 输入: nums [4,2,9,5,3] 输出: 3 解释: nums[1]、nums[3] 和 nums[4] 是质数。因此答…...
【Gin】项目搭建 一
环境准备 首先确保自己电脑安装了Golang 开始项目 1、初始化项目 mkdir gin-hello; # 创建文件夹 cd gin-hello; # 需要到刚创建的文件夹里操作 go mod init goserver; # 初始化项目,项目名称:goserver go get -u github.com/gin-gonic/gin; # 下载…...
C++ 和C#的差别
首先把眼睛瞪大,然后憋住一口气,读下去: 1、CPP 就是C plus plus的缩写,中国大陆的程序员圈子中通常被读做"C加加",而西方的程序员通常读做"C plus plus",它是一种使用非常广泛的计算…...
Vue2组件传值(通信)的方式
目录 1.父传后代 ( 后代拿到了父的数据 )1. 父组件引入子组件,绑定数据2. 子组件直接使用父组件的数据3. 依赖注入(使用 provide/inject API)1.在祖先组件中使用 provide2.在后代组件中使用 inject 2.后代传父 (父拿到了后代的数据)1. 子组件…...
【数据结构 - 时间复杂度和空间复杂度】
文章目录 <center>时间复杂度和空间复杂度算法的复杂度时间复杂度大O的渐进表示法常见时间复杂度计算举例 空间复杂度实例 时间复杂度和空间复杂度 算法的复杂度 算法在编写成可执行程序后,运行时需要耗费时间资源和空间(内存)资源 。因此衡量一个算法的好坏&…...
telegram支付
今天开始接入telegram支付,参考教程这个是telegram的官方说明,详细介绍了机器人支付API。 文章公开地址 新建机器人 因为支付是一个单独的系统,所以在做支付的时候单独创建了一个bot,没有用之前的bot了,特意这样将其分开。创建bot的方法和之前不变,这里不过多介绍。 获…...
elasticsearch-6.8.23的集群搭建过程
三个节点的 ElasticSearch 集群搭建步骤 准备三台机器:28.104.87.98、28.104.87.100、28.104.87.101 和 ElasticSearch 的安装包 elasticsearch-6.8.23.tar.gz ----------------------------- 28.104.87.98,使用 root 用户操作 ----------------------…...
javascript输出语法
javascript输出有三种方式 一种是弹窗输出,就是网页弹出一个对话框,弹出输出内容 语法是aler(内容) 示例代码如下 <body> <script> alert(你好); </script> </body> 这段代码运行后网页会出现一个对话框,弹出你…...
仓库管理系统26--权限设置
原创不易,打字不易,截图不易,多多点赞,送人玫瑰,留有余香,财务自由明日实现 1、权限概述 在应用软件中,通常将软件的功能分为若干个子程序,通过主程序调用。那么,通过…...
d3dx9_43.dll丢失怎么解决?d3dx9_43.dll怎么安装详细教程
在使用计算机中,如果遇到d3dx9_43.dll丢失或许找不到d3dx9_43.dll无法运行打开软件怎么办?这个是非常常见问题,下面我详细介绍一下d3dx9_43.dll是什么文件与d3dx9_43.dll的各种问题以及d3dx9_43.dll丢失的多个解决方法! 一、d3dx9…...
[C++] 退出清理函数解读(exit、_exit、abort、atexit)
说明:在C中,exit、_exit(或_Exit)、abort和atexit是用于控制程序退出和清理的标准库函数。下面是对这些函数的详细解读: exit 函数原型:void exit(int status);作用:exit函数用于正常退出程序…...
代码随想录(回溯)
组合(Leetcode77) 思路 用递归每次遍历从1-n得数,然后list来记录是不是组合到k个了,然后这个每次for循环的开始不能和上一个值的开始重复,所以设置个遍历开始索引startindex class Solution {static List<List<…...
编译原理1
NFA&DFA 在正规式的等价证明可以借助正规集,也可以通过有限自动机DFA来证明等价,以下例题是针对DFA证明正规式的等价,主要步骤是①NFA;②状态转换表; ③状态转换矩阵; ④化简DFA; 文法和语…...
【信息系统项目管理师知识点速记】组织通用管理:流程管理
23.2 流程管理 通过流程视角能够真正看清楚组织系统的本质与内在联系,理顺流程能够理顺整个组织系统。流程是组织运行体系的框架基础,流程框架的质量影响和决定了整个组织运行体系的质量。把流程作为组织运行体系的主线,配备满足流程运作需要的资源,并构建与流程框架相匹配…...
前端 JS 经典:箭头函数的意义
箭头函数是为了消除函数的二义性。 1. 二义性 函数的二义性指函数有不同的两种用法,就造成了二义性,函数的两种用法:1. 指令序列。2. 构造器 1.1 指令序列 就是调用函数,相当于将函数内部的代码再从头执行一次。 1.2 构造器 …...
地震勘探——干扰波识别、井中地震时距曲线特点
目录 干扰波识别反射波地震勘探的干扰波 井中地震时距曲线特点 干扰波识别 有效波:可以用来解决所提出的地质任务的波;干扰波:所有妨碍辨认、追踪有效波的其他波。 地震勘探中,有效波和干扰波是相对的。例如,在反射波…...
C++:std::is_convertible
C++标志库中提供is_convertible,可以测试一种类型是否可以转换为另一只类型: template <class From, class To> struct is_convertible; 使用举例: #include <iostream> #include <string>using namespace std;struct A { }; struct B : A { };int main…...
DAY 47
三、通道注意力 3.1 通道注意力的定义 # 新增:通道注意力模块(SE模块) class ChannelAttention(nn.Module):"""通道注意力模块(Squeeze-and-Excitation)"""def __init__(self, in_channels, reduction_rat…...
2024年赣州旅游投资集团社会招聘笔试真
2024年赣州旅游投资集团社会招聘笔试真 题 ( 满 分 1 0 0 分 时 间 1 2 0 分 钟 ) 一、单选题(每题只有一个正确答案,答错、不答或多答均不得分) 1.纪要的特点不包括()。 A.概括重点 B.指导传达 C. 客观纪实 D.有言必录 【答案】: D 2.1864年,()预言了电磁波的存在,并指出…...
对WWDC 2025 Keynote 内容的预测
借助我们以往对苹果公司发展路径的深入研究经验,以及大语言模型的分析能力,我们系统梳理了多年来苹果 WWDC 主题演讲的规律。在 WWDC 2025 即将揭幕之际,我们让 ChatGPT 对今年的 Keynote 内容进行了一个初步预测,聊作存档。等到明…...
屋顶变身“发电站” ,中天合创屋面分布式光伏发电项目顺利并网!
5月28日,中天合创屋面分布式光伏发电项目顺利并网发电,该项目位于内蒙古自治区鄂尔多斯市乌审旗,项目利用中天合创聚乙烯、聚丙烯仓库屋面作为场地建设光伏电站,总装机容量为9.96MWp。 项目投运后,每年可节约标煤3670…...
12.找到字符串中所有字母异位词
🧠 题目解析 题目描述: 给定两个字符串 s 和 p,找出 s 中所有 p 的字母异位词的起始索引。 返回的答案以数组形式表示。 字母异位词定义: 若两个字符串包含的字符种类和出现次数完全相同,顺序无所谓,则互为…...
浪潮交换机配置track检测实现高速公路收费网络主备切换NQA
浪潮交换机track配置 项目背景高速网络拓扑网络情况分析通信线路收费网络路由 收费汇聚交换机相应配置收费汇聚track配置 项目背景 在实施省内一条高速公路时遇到的需求,本次涉及的主要是收费汇聚交换机的配置,浪潮网络设备在高速项目很少,通…...
算法:模拟
1.替换所有的问号 1576. 替换所有的问号 - 力扣(LeetCode) 遍历字符串:通过外层循环逐一检查每个字符。遇到 ? 时处理: 内层循环遍历小写字母(a 到 z)。对每个字母检查是否满足: 与…...
处理vxe-table 表尾数据是单独一个接口,表格tableData数据更新后,需要点击两下,表尾才是正确的
修改bug思路: 分别把 tabledata 和 表尾相关数据 console.log() 发现 更新数据先后顺序不对 settimeout延迟查询表格接口 ——测试可行 升级↑:async await 等接口返回后再开始下一个接口查询 ________________________________________________________…...
