Android Multi-Screen Application

浪子不回头ぞ 提交于 2019-12-07 03:01:31

问题


How do you handle multiple screens in an android application? I have developed with the tab bar at the bottom without problem, however what I am wanting to do is replace all the content on the screen with the content from a new .xml layout file I have created in the project. Additionally, how would I tie the back end code to the new layout file? I'm sure this question probably exists already and is googleable (may have made up a new word). However, I don't know exactly what it is that I am looking for. Thanks in advance for your help.


回答1:


What you need to do is, create a new Activity and add it to the AndroidManifest.xml:

<activity android:name="ActivityClassName" android:label="Label for the Activity"></activity>

and can be called in a method:

public void startActivity() {
    Intent someName = new Intent(CurrentClass.this, ActivityClassName.class);
    startActivity(someName);
}



回答2:


Android applications generally use a separate Activity for each screen, and switch between them using Activity.startActivity and Activity.startActivityForResult. You can pass arbitrary data to an Activity via Intent.putExtra.

Hope this helps,

Phil Lello




回答3:


It really depends on how you want your application to flow.

Let's consider the scenario where a user does the following:

  1. Starts your first activity
  2. Presses the 2nd tab
  3. Presses the 3rd tab
  4. Presses the back button

If you use a separate activity for each screen, then the following would happen

  1. Activity 1 is started
  2. Activity 2 is started
  3. Activity 3 is started
  4. Activity 3 is closed, user returns to Activity 2

(in this case pressing the back button again would you take you back to Activity 1, and pressing it again would exit your application)

If you used one activity for all the tabs, then the following would occur

  1. Activity 1 is started
  2. Activity 1 sets tab content to tab 2 content
  3. Activity 1 sets tab content to tab 3 content
  4. Activity 1 is closed, user returns to home screen

If you are using a screen with tabs, then the second method (a single Activity with a TabHost or similar) is the preferred method, otherwise the user will end up making a large activity-stack just switching between tabs (meaning if they switch between tabs a lot they'll have to press the back button a lot of times to exit).

If you want to go for the single activity approach, then do some research on TabHost and TabContentFactory. In the createTabContent method of your factory you can inflate a View/layout from XML to set as the tab content using View.inflate. Look those up and come back ask another question if you get stuck ;)




回答4:


i think you may want to play with more than one activity.... you can have multiple activities and one xml for each of them... in this way you can have different screens... check these links. Multiple Activities, Creating an Activity.... hope this helps...



来源:https://stackoverflow.com/questions/5584025/android-multi-screen-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!