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.
It is certainly not a sensible way to do stuffs.
You can however use a ViewFlipper by which you can change the screen layouts. This way you can stay in the same class and change your screen design.
http://developer.android.com/reference/android/widget/ViewFlipper.html
Related
I am building app right now. I am trying to follow all design patterns and google suggestions for building responsive apps.
Firstly, my app will contain navigation drawer.Of course my app will have several activities. So I have searched the best way to have navigation drawer on all activities, I found that the most correct way is to use some BaseActivity class which will have navigation drawer in its layout and framelaout for storing each activity representation(container for fragment). It can hold fragment, but the problem is that only one fragment.
So I have faced this problem. I am going to design following activity
So as in the picture I wanna to have image slider at the top , and some other layout parts under this slider for example grid layout, list or something other.
I think it would be better to separate image slider and other part, for example when my scree will be in landscape orientation it should be replaced but something other.
Futhermore others activites also gonna to have several independent parts for example list and anything other widget.
But as far as my activities should extend BaseActivity class, they would have only one place(container) for storing fragment.
I have tried to think about ways to solve this problem , and I have only one idea is to create several fram layouts in base activity(equal to max fragments used on child activities) and setting them visible and invisible depending on needs, but this approach pretended to be only way of hidding problem.
I don't know what is the most correct way to implement such type of application, so I need help or advices from more experienced developers to build my app correctly and bring user good experience.
I hope you can help me.
Thanks.
To start with, the container in your BaseActivity does not have to necessarily be a FrameLayout. For example it could easily be a LinearLayout with android:orientation="vertical", so that all fragments you add in it will stack one below the other.
Also each fragment can has other nested fragments in itself (although that's generally not the best practice, as usually it indicates some bad UX decisions).
Both those said, I think you just use the first point I made here. Now if you choose this one, I'd expect the question how to handle tablets and other big screens? Best way to handle them is to create a new landscape layout for your BaseActivity, where the fragments container might be different, for example a RelativeLayout, a LinearLayout with orientation="horizontal" and so on.
Good luck!
I'm currently developing a little application that uses a login screen and a main screen. I'd been watching how another developers had been made the screen switch, some developers adds and remove fragments on run time, anothers have an Activity for each view (in my case that will be a MainActivity with the main_activity layout, and the LoginActivity with the login_activity layout). And I don't know wich is the way to go. I think that have a fragment for each view will be the solution with more sense, but I want to listen some opinions before continue.
There might be others who disagree with me, but in my opinion, Fragments are better suited when you want to keep a part of the screen static and change something in the other part (analogous to AJAX in websites).
Activities should be used for individual views in those cases where there is only one thing happening on the application front-end.
On the other hand if you have a Gmail like layout (with static links to Inbox, Sent, etc. on the left hand side and a dynamic list of mails on the right hand side of the screen), Fragments is the answer.
But since you have two different screens for layout and main, in my opinion, it would be neat if you used different Activities for the layouts and used Intents to navigate around.
For two completely different Activitys such as Login and Main I think you want to use two different Layouts and two separate Activitys and no need for fragments. However, you may want to use fragments inside any of them as #swayam suggested depending on what you want to do inside of them. You need to look at the docs and decide which is better suited for your needs. No one can really decide that for you.
Activity
Fragments
i m just wondering about some android ui aspects where i need some advices! Might be, that my idea so far is not the best...
Basically I m working on an app, which plays streams in a player (main screen). The user can select streams in a second screen (tabbar screen), where he can switch between three different lists, each one is in one of the tabs and each tabbarclick starts a new activity (i m not using an ActionBar or sth, I just created an own UI element which consist of three icons, current one selected and the other two starting a new Activity):
ListViewActivity1: dynamically created ViewFlipper with nested ListViews (f.e. country->state->city..) from a database
ListViewActivity2: simple ListView with favorits from ListViewActivity1
ListViewActivity3: simple ListView with UserGenerated content
So far it s working great but I m starting to struggle...
Everytime the user enters the tabbar screen again, I want him to be exactly at the last ListView where he was. So basically I m looking for a way to store the different screens if the user leaves them. I came across onSaveInstanceState(Bundle savedInstanceState), but this doesn't really fit my needs. The ListViewActivity 1 is a really complex list with up to six levels sometimes, which I really don't want to transport in a savedInstanceState! Is there another way?
Actually if I go back in the BackStack, this really saves the different states like I want it to. So it is possible, I just don't find anything like this..
So, question 1: Is there a way to save a view like the BackStack does?
question 2: Is this whole idea of ui-implementation a good solution to set up an app?
thanks for any input!
I am making my first android application with the ActionBarSherlock.
The application will always have an action bar consisting of 3 tabs (first tab selected by default).
The app could be extended for use with a tablet.
I have been searching the web, and following the android development guides, however I am finding a few things confusing.
The first tab screen will be a list view with a list of items, onitemselected should send the user to a screen which features more details about that item.
When should I use a fragment? Should each tab be a fragment?
Or, should each tab call a new activity, which consists of fragments?
And, if using fragments, should I place them in different classes, or embed them within an activity??
Appreciate any help, thanks.
you should probably read these two links first.
http://android-developers.blogspot.com/2011/09/preparing-for-handsets.html
http://android-developers.blogspot.com/2011/02/android-30-fragments-api.html
If you plan to make an app that work on both phone and tablet. It is a good idea to use a fragment, and then use a shell activity to wrap that fragment.
My experience with Fragments is mostly on ViewPager, so I am not entirely sure if it applies here.
In Android, you should use Fragments as much as possible. As a general rule of thumb, imagine you are translating the UI from phones to tablets, elements that can stay together in the same configuration should be a Fragment.
There is a Fragment subclass called ListFragment, so you might want to look into that for your first tab. (ListFragment is for Fragment like ListActivity is for Activity)
There is also a tutorial I found to deal with fragments. Did not really look into it but I hope it helps.
http://android.codeandmagic.org/2011/07/android-tabs-with-fragments/
As for ActionBar / ActionBarSherlock, I have absolutely no experience withit so someone might want to add to that.
I want to create an activity, which shows a question with 4 answers, and at the bottom of the screen i want to place a timer.
I have already found timer example, and i created a question with the answers. the problem that they are 2 different projects and activities, and i am looking for the best way to implement it. i think i can't show 2 activities on one screen, but i can show 2 views or shell i use the ViewGroup, or maybe to copy-paste one of the activities code to another ( its the easiest way but probably the most ugliest way to implement it).
please tell me what is the best way, that i will study and not to waste time to study all the ways and only then to choose one of them.
welcome to StackOverflow.
You are correct in that you cannot display two activities at once. You must instead look into how layouts work in Android by reading some tutorials on the Android developer guide.
For your layout, I would recommend using a LinearLayout with four TextView objects inside it containing the questions (and perhaps your EditText objects below them) as well as your timer. Make sure they are all inside a ScrollView so the software keyboard doesn't force it all to be squeezed up. This is how I would approach it, but I encourage you to read about how layouts work and use the XML resources.
The Notepad tutorial is an excellent way to get started with views and text entry, as well as using SQLite databases.