Android Xamarin c# 替换 Fragment 后无法更新视图
创始人
2024-08-19 12:30:17
0

问题描述: 在使用Android Xamarin开发时,使用C#替换Fragment后,发现无法更新视图。

解决方法:

  1. 确保在替换Fragment之前已经初始化了相关的视图组件和数据。
  2. 确保在替换Fragment后调用了相关的更新视图的方法。
  3. 确保在更新视图的方法中使用了正确的视图组件的引用。
  4. 如果视图组件是在Fragment的布局文件中定义的,可以尝试通过重新加载布局文件来更新视图:
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
    // 加载布局文件
    View view = inflater.Inflate(Resource.Layout.fragment_layout, container, false);
    
    // 初始化视图组件和数据
    TextView textView = view.FindViewById(Resource.Id.textView);
    textView.Text = "Hello World";
    
    return view;
}

public void UpdateView()
{
    // 更新视图
    TextView textView = View.FindViewById(Resource.Id.textView);
    textView.Text = "Updated Text";
}

在替换Fragment后,可以调用UpdateView方法来更新视图:

// 替换Fragment
FragmentTransaction transaction = FragmentManager.BeginTransaction();
transaction.Replace(Resource.Id.container, new MyFragment());
transaction.Commit();

// 更新视图
MyFragment fragment = FragmentManager.FindFragmentById(Resource.Id.container);
fragment.UpdateView();

通过以上方法,可以在替换Fragment后更新视图。

相关内容

热门资讯

德州hhpoker脚本!智星德... 您好,智星德州插件最新版本更新内容详解这款游戏可以开挂的,确实是有挂的,需要了解加去威信【48527...
wepoker辅助器是真的吗!... wepoker辅助器是真的吗!wepoker破解是真的还是假的(透视)方法-本来分享是有挂暗藏猫腻,...
wepoker有没有插件!we... wepoker有没有插件!wepokerplus开挂(透视)挂-其实详细有挂1、wepoker有没有...
pokerworld修改器!p... pokerworld修改器!pokemmo免费脚本(透视)插件-好像开挂真的有挂1、打开软件启动之后...
德州透视是真的吗!hhpoke... 德州透视是真的吗!hhpoker一直输有挂吗(透视)app-切实关于真的有挂1、在hhpoker一直...
wepoker怎么获得好牌!u... wepoker怎么获得好牌!uupoker透视(透视)教程-一贯解迷是有挂1、wepoker怎么获得...
hhpoker破解工具!德普之... hhpoker破解工具!德普之星私人局透视(透视)挂-总是详情是有挂1、玩家可以在德普之星私人局透视...
hhpoker是真的还是假的!... hhpoker是真的还是假的!pokermaster脚本(透视)工具-一贯教你是有挂1、完成hhpo...
wepoker如何设置透视!w... wepoker如何设置透视!wepoker有人用过吗(透视)器-好像揭幕有挂1.wepoker如何设...
wepoker有人用过吗!we... wepoker有人用过吗!wepoker私人定制透视(透视)方法-一直科普真的有挂1、该软件可以轻松...