Android标签:Acitivities或Views?(Android Tabs: Activities or Views?)

编程入门 行业动态 更新时间:2024-10-25 03:18:04
Android标签:Acitivities或Views?(Android Tabs: Activities or Views?)

我正在尝试编写一个小的Android应用程序来存储食谱作为练习。 要添加新配方,我正在尝试使用标签。 有三个标签,

配料 脚步 媒体

我希望“Ingredients”有一个ListView,“Steps”有一个ListView,而“Media”有一个图库。 我将通过选项菜单中的一些选项添加新的成分,步骤和媒体。 完成后,我想将所有内容写入SQLite数据库。

我想知道我是否应该为每个标签使用不同的活动或只是不同的视图?

如果我使用不同的活动,是否很难在活动之间传递信息?

如果我使用不同的视图,那么视图是否必须是同一布局文件的一部分? 例如, TabWidgets上的教程执行以下操作:

<FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/textview1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="this is a tab" /> <TextView android:id="@+id/textview2" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="this is another tab" /> <TextView android:id="@+id/textview3" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="this is a third tab" /> </FrameLayout>

所以所有TextView都在同一个FrameLayout中,每个TextView只用于一个选项卡。 如果视图更复杂,我认为这会有点混乱,例如嵌套在其他东西中的东西,它再次嵌套在其他东西中。 对每个选项卡使用不同的活动,我可以为每个选项卡指定不同的布局文件。

任何建议,将不胜感激。

I'm trying to write a little Android application to store recipes as practice. To add a new recipe, I'm trying to use tabs. There are three tabs,

Ingredients Steps Media

I'd like "Ingredients" to have a ListView, "Steps" to have a ListView, and "Media" to have a gallery of images. I'm going to add new ingredients, steps, and media through some option in the options menu. When finished, I'd like to write everything to an SQLite database.

I'm wondering if I should use different activities or just different views for each tab?

If I use different activities, would it be hard to pass information between the activities?

If I use different views, do the views all have to be part of the same layout file? For example, the tutorial on TabWidgets does the following:

<FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/textview1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="this is a tab" /> <TextView android:id="@+id/textview2" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="this is another tab" /> <TextView android:id="@+id/textview3" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="this is a third tab" /> </FrameLayout>

So all the TextViews are within the same FrameLayout, with each TextView being used for only one tab. I think this would be a little confusing if the views were more complex, e.g. something nested within something else, which is again nested within something else. Using different activities for each tab, I can specify a different layout file for each tab.

最满意答案

我想知道我是否应该为每个标签使用不同的活动或只是不同的视图?

使用活动作为选项卡内容已被弃用。 您仍然可以这样做,但如果您刚刚开始使用此项目,那么使用视图将是一种更好的方法。

如果我使用不同的活动,是否很难在活动之间传递信息?

是和否,但这取决于您的专业水平 - 在活动之间传递信息通常涉及使用Intents(尽管还有其他方法)。 虽然这是相同的,无论它们是独立的还是标签环境的一部分都没有任何区别,但它确实需要一些思考。

如果我使用不同的视图,那么视图是否必须是同一布局文件的一部分?

不,但是当您使用TabActivity开始时,您可能想要在该教程中尝试该方法。

可以有不同的布局(适用于任何类型的活动)并根据需要自己进行膨胀,但这是一个更复杂的主题。

I'm wondering if I should use different activities or just different views for each tab?

Using Activities as Tab content has been deprecated. You can still do it but if you're just starting out with this project then using Views instead would be a better approach.

If I use different activities, would it be hard to pass information between the activities?

Yes and no, but it depends on your level of expertise - passing information between Activities generally involves using Intents (although there are other ways). Although this is the same whether they're stand-alone or part of a tabbed environment doesn't make any difference but it does take some thinking about.

If I use different views, do the views all have to be part of the same layout file?

No but you might want to experiment with the approach in that tutorial when using a TabActivity to get started.

It's possible to have different layouts (for any type of Activity) and inflate them yourself as necessary but that's a more complex topic.

更多推荐

本文发布于:2023-08-06 15:09:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1451168.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标签   Acitivities   Android   Activities   Tabs

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!