星空网 > 软件开发 > Java

getSupportFragmentManager要用在FragmentActivity及其子类中

getSupportFragmentManager要用在FragmentActivity及其子类中!!

 

关于安卓抽屉导航!!

 * 自定义侧边栏

 

getSupportFragmentManager要用在FragmentActivity及其子类中

 

 

 

getSupportFragmentManager要用在FragmentActivity及其子类中

 

      创建一个Fragment:CarlozLibFragment.java,并为其创建一个布局carloz_lib_webview.

 

getSupportFragmentManager要用在FragmentActivity及其子类中
public class CarlozLibFragment extends Fragment {  private String TAG = "CARLOZ";  @Override  public View onCreateView(LayoutInflater inflater, ViewGroup container,      Bundle savedInstanceState) {    // TODO Auto-generated method stub    View root = inflater.inflate(R.layout.carloz_lib_webview, container, false);        WebView wv =(WebView)root.findViewById(R.id.wv);    Log.d(TAG, "load url: carloz lib");    wv.loadUrl("http://carloz.duapp.com");        return root;  }}
getSupportFragmentManager要用在FragmentActivity及其子类中

 

      将NavigationDrawerFragment.java 中 onCreateView中ListView相关内容删除,用自定义布局 diy_slider_content.

 

getSupportFragmentManager要用在FragmentActivity及其子类中
@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,    Bundle savedInstanceState) {  View root = inflater.inflate(R.layout.diy_slider_content, container, false);    root.findViewById(R.id.btnJump).setOnClickListener(new OnClickListener() {    @Override    public void onClick(View v) {      if (mDrawerLayout != null) {        // 隐藏侧边栏        mDrawerLayout.closeDrawer(mFragmentContainerView);      }      if(mCallbacks != null) {        mCallbacks.onGotoCarlozLibClicked();      }    }  });    return root;}
getSupportFragmentManager要用在FragmentActivity及其子类中

 

      onGotoCarlozLibClicked()这个接口是自定义接口,在 静态接口 NavigationDrawerCallbacks 中新增定义

 

getSupportFragmentManager要用在FragmentActivity及其子类中
public static interface NavigationDrawerCallbacks {  /**   * Called when an item in the navigation drawer is selected.   */  void onNavigationDrawerItemSelected(int position);    // 通过回调传给主界面  void onGotoCarlozLibClicked();}
getSupportFragmentManager要用在FragmentActivity及其子类中

 

    需要在主界面SliderActivity中实现该回调方法, 因为主界面实现了 NavigationDrawerFragment.NavigationDrawerCallbacks 接口

 

getSupportFragmentManager要用在FragmentActivity及其子类中
@Overridepublic void onGotoCarlozLibClicked() {  // 需要实现 NavigationDrawerFragment.java Callback中新增的方法  // 在容器 container 中添加 fragment CarlozLibFragment  getSupportFragmentManager().beginTransaction()      .replace(R.id.container, new CarlozLibFragment())      .commit();}
getSupportFragmentManager要用在FragmentActivity及其子类中

 

运行结果如下:

 

getSupportFragmentManager要用在FragmentActivity及其子类中

 

这里引用:http://www.cnblogs.com/carlo/p/4726719.html

 




原标题:getSupportFragmentManager要用在FragmentActivity及其子类中

关键词:get

get
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

意大利消费:https://www.goluckyvip.com/tag/47767.html
意大利小包:https://www.goluckyvip.com/tag/47768.html
美国快递业:https://www.goluckyvip.com/tag/4777.html
意大利邮编:https://www.goluckyvip.com/tag/47771.html
意大利站fba:https://www.goluckyvip.com/tag/47772.html
意大利制造:https://www.goluckyvip.com/tag/47774.html
松花蛋是哪里的特产松花蛋的产地:https://www.vstour.cn/a/411229.html
怪物在游轮上复活的电影 怪物在游轮上复活的电影叫什么:https://www.vstour.cn/a/411230.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流