最好的方式来显示多个的setContentView Android中最好的、多个、方式、Android

2023-09-12 06:07:06 作者:柠檬ソ琉璃夏

我是pretty的新的Andr​​oid所以我很抱歉,如果这个问题听起来很愚蠢,以任何方式。

我试图创建一个应用程序参加了许多类,但2个主要的将是学生和课程。

我打算使用标签浏览与学生和课程是在我的TabHost 2标签。

课程页面,例如会列出当前所有在系统中的选项菜单中的课程的添加过程,然后会弹出一个添加课程屏幕(课程选项卡中,但更改视图)。

所以,我的问题...

我打算设置一个onclick的选项菜单项,它将调用的setContentView显示增加,而不是开始呈现出新布局的新活动新课程的布局。

这听起来像一个明智的方式来做到这一点?如果不是这将是一个更好的办法?

我所有的课程逻辑将包含在课程类中,所以我想我所有的code被包含在那里,而无需创建一个类/活动课程列表,添加过程中,查看课程等等。

我希望这是有道理的。

解决方案        

这听起来像一个明智的方式来做到这一点?如果不是这将是一个更好的办法?

  

没有,这不是一个明智的方式来做到这一点。您应该打开新的活动;这是Android的方式。也许你正在试图模仿不打开新窗口或东西iPhone的标签样式。

如果你仍然想这样做,你最好使用的ActivityGroup (有教程在那里),这恕我直言,是一个痛苦的使用驴。

Android 开发之漫漫长途 Ⅲ Activity 的显示之 Window和View 2

I'm pretty new to Android so I apologize if this question sounds stupid in any way.

I'm trying to create an attendance application with many classes but the 2 main ones will be Student and Courses.

I plan to use tabs to navigate with Student and Courses being the 2 tabs in my TabHost.

The Course page for example will list all of the courses currently in the system with an options menu for Adding a course which will bring up an Add Course screen (within the Course tab but changing the view).

So, to my question...

I plan to set an onclick for the options menu item which will call setContentView to display the add new course layout instead of starting a new Activity showing a new layout.

Does this sound like a sensible way to do this? If not what would be a better approach?

All my course logic will be contained within the Course class and so I want all of my code to be contained within there without having to create a class/activity for a course list, adding a course, viewing a course etc.

I hope this makes sense.

解决方案

Does this sound like a sensible way to do this? If not what would be a better approach?

No, it's not a sensible way to do so. You should open the new activity; that's the Android way. Maybe you are trying to imitate the iPhone tabs style which don't open new windows or something.

If you still want to do so, you better use ActivityGroup (there are tutorials out there), which IMHO is a pain the ass to use.