导航抽屉:使用片段并添加监听器改变布局 [英] Navigation drawer : changing layouts using fragment and adding listeners

查看:155
本文介绍了导航抽屉:使用片段并添加监听器改变布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想新的导航抽屉添加到我的应用程序,而不是改变形象(因为它们是在谷歌例所示),我设法改变片段内的布局。

I'm trying to add the new Navigation drawer to my app and instead of changing images(as they are shown in the google example) I manage to change layouts inside the fragment.

的问题是,改变布局后我没有布局内的按钮的任​​何访问和其它的目的。

The problem is that after changing a layout I don't have any access to the buttons and other objects inside the layout.

我如何才能访问到在当前显示的按钮和其他对象
inflatered布局,并设置监听器?

How can I get access to the buttons and other objects that are shown in the current inflatered layout, and set listeners?

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{ 
switch(pageNum)
{ 
case 0: rootView = inflater.inflate(R.layout.groups_layout, container, false);
break;
case 1: rootView = inflater.inflate(R.layout.schedule_layout, container, false);
break; 
case 2: rootView = inflater.inflate(R.layout.courses_layout, container, false);
break;
} 
  theView = rootView; 
  return rootView; 
 } 
}

先谢谢了。

推荐答案

你应该做的是使用多个片段和交换机之间的抽屉里。然后只给每个片段不同的布局,这里有一个很好的例子
http://manishkpr.webheavens.com/android-navigation-drawer-example-using-fragments/

what you should do is use multiple fragments and switch between them with the drawer. then just give each fragment a different layout, here's a great example http://manishkpr.webheavens.com/android-navigation-drawer-example-using-fragments/

这篇关于导航抽屉:使用片段并添加监听器改变布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆