使用导航抽屉改变片段(?)的布局或活动 [英] change fragment(?) layout or activity using a navigation drawer

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

问题描述

下面EDITED

IM真正的新开发的Andr​​oid和Java,即时通讯并排阅读吨的教程和电子书边学习基础知识,并做了一些实验同时谷歌上搜索我需要什么。

im really new to android development and java, im reading tons of tutorial and ebook side by side to learn basics and doing some experiment meanwhile googling what I need.

截至目前我尝试使用新的抽屉式导航我跟着指引,我设法把它与节名衔起了变化工作的所选项目等。现在我打beucase我不知道如何存档什么,我想下一步该怎么做。

as of now im trying to use the new Navigation Drawer I followed the guideline and I managed to have it working with section names title changin on item selected and so on. now I struck beucase I have no idea how to archive what I want to do next

我想,当我在抽屉里,例如单击某个项目的首页它把我带到一个页在那里我有我的具体网页特定布局创建的所有东西它像textviews和图像所有静态的东西,所以我没有与他们做任何事情。

I want that when I click an item in the drawer for example home it bring me to a "page" where I have all the stuff I created in a particular layout for the specific "page" its all static stuff like textviews and images so I don't have to do anything with them.

我要创建活动和抽屉的列表视图每个项目的布局和(不知道怎么还)启动所选的项目活动。或者我可以做一些像创建一个片段onTheFly每次我ListView中点击一个项目,说:如果家里点击使用home.xml作为布局如果接触点击使用contact.xml的布局。

should I create an activity and a layout for every item on the listview of the drawer and (dunno how yet) start the activity on item selected. or can I do something like create a fragment onTheFly everytime I click an item in the listview and say it "if home clicked" use home.xml as layout" if "contact clicked" use contact.xml as layout.

感谢大家谁读了我的问题,并愿意提供帮助。

thanks to everyone who reads my problem and want to help.

kandros

修改

作为测试我的推杆进onItemClick上的排列位置pased的方法点击做点什么。作为测试我只是用在如else语句,看看位置== 2(这是接触诠释他listlayout)它的的setContentView(R.layout.contacts)

as a test I putted into onItemClick a method that pased on the array position clicked do something. as a test I just used at if else statement to see if position==2 (which is contact int he listlayout) it does setContentView(R.layout.contacts)

它的工作,但很明显,我失去了抽屉的接触布局东西,它不是嵌套到它。有一个更优雅的方式来实现我的目标,而不是使用一个开关,每个位置和使用的setContentView 修改被嵌套到澈抽屉里的布局? (甚至不知道它可能的,大概不会因为有平等的ID)

it does work but obviously I lose the drawer as the contacts layout stuff its not nested into it. there is a "more elegant" way to achieve my goal instead of use a switch for each position and use setContentView modifying any layout to be nested into che drawer? (don't even know if its possible , probably not as there's equals IDs)

@斯特凡编辑本作中的评论回复那里有没有足够多的空间。

@ Stefan edited this as theres not enought space in the comment reply

感谢斯特凡,谷歌的例子它使我更糊涂..和我确定的东西有大约片段塔一个非常小的事情偷偷摸摸的,我可能读10,000次,但我的大脑拒绝同化^^。
据我了解,在谷歌的例子,当你在项目点击在抽屉里,它创建一个新片段,使该片段取代没有在MainActivity的XML布局中的框架布局<出票人lisrview旁边的唯一的事情/ STRONG>这需要格兰屏的全部空间,然后所有的片段做是为了让code说要片段根据项目点击的列表视图阵列的位置来改变图像diplays行星ImageView的。我知道即时接近understad整个思考..它只是事情或C​​IGS的10包和一对夫妇的哭声/愤怒会议

thanks stefan, the google example it the thing that makes me more confused.. and im sure there a very little sneaky thing about fragment tha I probably read 10k times but my brain refuses to assimilate ^^ . as far I understood, in the google's example when you click in item in the drawer, it does create a new fragment and makes this fragment replace the only thing there is beside the drawer's lisrview in the MainActivity's xml layout a frame layout that takes all the space of teh screen then as all the fragment do is to diplays a planet imageview so the code says to the fragment to change that image based on the listview array position of the item click. I know im close to understad the whole think.. its just matter or 10 packs of cigs and a couple of cry/rage sessions

推荐答案

奥凯,这里的许多问题启动与一个组合那是pretty新的,不确定的呢。

Oke, a lot of starter questions here combined with one that's pretty new and undefined yet.

首先,您只需做启动一个新的活动;

First of all, you start a new Activity by simply doing;

this.startActivity(new Intent(this, ActivityClassName.class)); 

从任何活动(或片段,有点改变,以'本'='this.getActivity()')

From any Activity (or Fragment, a bit altered to 'this' = 'this.getActivity()' )

没有,如果你使用的活动或片段的事情,你永远需要创建一个类和属于XML视图。
你可以建立一些通用的,但大部分的时间你不想这样做。

No matter if you use Activities or Fragments, you will always have to create a class and a belonging xml view. You can build up something generic, but most of the time you don't want to do this.

关于这个问题,如果你要启动一个新的活动,或在抽屉点击后切换片段,我会说这就是还很难说。

About the question if you should start up a new Activity, or switch Fragments after a click on the Drawer, i'd say thats still hard to say.

在一般情况下,它是最简单和最,因为它应当到刚开始一个新的活动。作为活动应该等于一个可见的屏幕,可能有多个部件(可能是片段)。

In general, it is easiest and the most 'as it should' to just start a new Activity. As an Activity should equal a visible screen with possibly multiple parts (which could be Fragments).

然而在实践中,你会看到越来越多的谷歌应用程序(谷歌音乐,Play商店,新的Gmail ..),似乎放弃了这个想法,并用1活动,只有切换片段不断。

In practice however, you see more and more Google apps (Google Music, Play store, new Gmail..) that seem to abandon this idea and use 1 Activity which only switches Fragments constantly.

从技术上这种地方活动在应用程序的作用,它可以带来额外的困难。
视觉然而,转换是为更加顺畅,每个例子中,动作条保持不变,而这样的更多的是锚谷歌喜欢它的人。

Technically this sort of places the Activity in the Application role, which can bring extra difficulties. Visually however, the transitions are much smoother as, per example, the actionbar stays the same and like that is more the 'anchor' Google likes it to be.

但是,由于它似乎,他们正在切换在他们的教程片段,而不是开始活动,所以也许你应该尝试这种方式和上的新的做事方式最前沿:)

It seems however, that they are switching Fragments in their tutorial instead of starting Activities, so perhaps you should try it that way and be on the bleeding edge of the 'new way of doing things' :)

http://developer.android.com/training/implementing-导航/ NAV-drawer.html

这篇关于使用导航抽屉改变片段(?)的布局或活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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