如何从MainActivity访问和更新片段组件(SeekBar,TextBox等)?

时间:2014-05-11 08:43:00

标签: android android-fragments

我创建了一个支离破碎的布局,其中有两个片段FragmentA和FragmentB。 FragmentA包含一个搜索栏,即seekBar1。

如何从MainActivity设置此搜索栏的进度(seekBar1.setProgress(68))?

1 个答案:

答案 0 :(得分:1)

您可以通过以下方式找到活动中的片段:

YourFragment yourFragment = (YourFragment) getSupportFragmentManager().findFragmentById(R.id.pageview)

YourFragment yourFragment = (YourFragment) = getFragmentManager().findFragmentById(R.id.pageview)

另外,您可以使用findFragmentByTag方法。

调用公共函数,例如:

yourFragment.setSeekBarProgress(...)
相关问题