时可以手动调用的方法 onCreateView
A 片段
或者,如果没有,有一些方法我可以模拟这种调用?
我有一个 FragmentActivity
与tabHost。每个标签包含一个片段
,我想刷新片段
的看法时,我preSS的刷新按钮。更具体地讲,我想重新调用 onCreateView
方法。
我的code目前是这样的:
@覆盖
公共查看onCreateView(LayoutInflater充气,容器的ViewGroup,捆绑savedInstanceState){
//充气的布局该片段
鉴于= inflater.inflate(R.layout.fragment_hall,集装箱,假);
layoutExsternal =(RelativeLayout的)view.findViewById(R.id.layoutExsternal);
layoutHall =(RelativeLayout的)view.findViewById(R.id.layoutHall);
在里面();
返回查看;
}
[...]
@覆盖
公共布尔onOptionsItemSelected(菜单项项){
// TODO自动生成方法存根
Log.d(itemSelected1,this.getClass()getSimpleName());
开关(item.getItemId()){
案例R.id.menu_refresh:
//这里我要插入的刷新Ø重绘的方法
返回true;
}
返回super.onOptionsItemSelected(项目);
}
解决方案
我已经解决了我的问题。我用自己取代目前的片段,但在此之前我已保存的当前片段的引用,然后我关闭当前片段的生命周期中调用的onDestroy()。我记得有newFragment变量。
开关(item.getItemId()){
案例R.id.menu_refresh:
//这是code刷新片段。
FragmentManager经理= getActivity()getSupportFragmentManager()。
FragmentTransaction英尺= manager.beginTransaction();
片段newFragment =这一点;
this.onDestroy();
ft.remove(本);
ft.replace(container.getId(),newFragment);
//容器是当前片段的的ViewGroup
ft.addToBackStack(空);
ft.commit();
返回true;
}
Is it possible to manually call the method onCreateView
in a Fragment
or, if not, is there some way I can simulate this invocation?
I have a FragmentActivity
with tabHost. Each tab contains a Fragment
and I want to refresh the Fragment
's view when I press the "Refresh" button. More specifically, I want to re-call the onCreateView
method.
My code currently looks like:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
// Inflate the layout for this fragment
view= inflater.inflate(R.layout.fragment_hall, container, false);
layoutExsternal = (RelativeLayout) view.findViewById(R.id.layoutExsternal);
layoutHall = (RelativeLayout) view.findViewById(R.id.layoutHall);
init();
return view;
}
[...]
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
Log.d("itemSelected1", this.getClass().getSimpleName());
switch (item.getItemId()) {
case R.id.menu_refresh:
//HERE I want to insert a method for refresh o redraw
return true;
}
return super.onOptionsItemSelected(item);
}
解决方案
I have resolved my question. I replace the current fragment with itself, but before I have saved a reference of current fragment and then i close life cycle of current fragment invoking onDestroy(). I recall it with "newFragment" variable.
switch (item.getItemId()) {
case R.id.menu_refresh:
//THIS IS THE CODE TO REFRESH THE FRAGMENT.
FragmentManager manager = getActivity().getSupportFragmentManager();
FragmentTransaction ft = manager.beginTransaction();
Fragment newFragment = this;
this.onDestroy();
ft.remove(this);
ft.replace(container.getId(),newFragment);
//container is the ViewGroup of current fragment
ft.addToBackStack(null);
ft.commit();
return true;
}
上一篇:多在AndroidAndroid
下一篇:总是让会话状态:CLOSED_LOGIN_FAILED,令牌:{AccessToken令牌:ACCESS_TOKEN_REMOVED在Facebook的Android SDK3.0。令牌、状态、A