如何获得View的FragmentManager
?如何通过视图ID获取FragmentManager?
假设我有一个这样的布局:
<?xml version="1.0" encoding="utf-8"?>
...
<fragment android:name="com.example.MyFragment"
android:id="@+id/thefragmentsid" >
</fragment>
...
这里是我的伪代码(我知道,即使没有FragmentView
存在,但我想你明白我的意思)
FragmentView fw = (FragmentView) activity.findViewById(R.id.thefragmentsid);
FragmentManager goal = fw.getFragment().getFragmentManager();
这里是一个示例用例:
public class MyFragment extends Fragment{
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.my_fragments_view, container, false);
}
}
public class MainActivity extends FragmentActivity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViewById(R.id.thefragmentsid).setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event){
FragmentView fw = (FragmentView) findViewById(R.id.thefragmentsid);
FragmentManager fm = fw.getFragment().getFragmentManager();
// Do something with the fragment manager
return false;
}
});
}
}
编辑:我无法以任何方式访问任何Fragment
-Object。也许有一种隐藏的方式,但正是我所要求的!
下一个修改:(只是为了完成问题)我使用Google支持包! PS:我不想给太多介入的信息,因为这是一个普遍的问题,需要一个普遍的答案,偶尔会出现。
不仅我发布的链接100%回答你的问题,但我发布了一个例子。你还想要什么? – 2011-12-29 19:35:05
@willmel 1)当然,我是一名android开发人员,并且从未见过您正在谈论的链接 - 别名_ android开发站点_。梦想^^不,我无法在Android指南中找到答案。 2)我真的很抱歉,但我无法看到你回答的答案。这听起来比想象的更加讨厌,我只是想知道你是否仔细阅读我的问题(我已经做了一些编辑)。如果您确定您的答案是正确的,请您尝试以我能理解的方式对它进行配置? – Matmarbon 2011-12-29 21:12:59
也许我真的不明白关于碎片的一些重要的事情,但在这种情况下,请尝试教给我,我愿意学习! – Matmarbon 2011-12-29 21:14:28