Android how to change views? - android

Basically I need some suggestions which is the best way to switch views in my situation. My Application has 5 different tabs. In every single tab I'm using activity manager to start as many activities that I need inside this tab. Now I have a little problem. In one of the tabs I need to create something like three different tabs. In second tabs I used 3 buttons, which switch the views via viewflipper. But now I have like 2 or 3 views inside every new tab (or button) which I need to switch. I did it with viewflipper but it's actually not what I want, because I want to use back button to switch between views.
Example:
MAIN TAB BAR : ONE TWO THREE FOUR FIVE
SECOND TAB BAR INSIDE TAB THREE / OR JUST THREE BUTTONS : TAB-A TAB-B TAB-C
IN TAB-A I have only one view.
IN TAB-B I have 2 views. View 1 is a listView and onItemClick switch view 2.
IN TAB-C I have same scenario like in TAB-B.
P.S. View 1 and View 2 directly can change to TAB-C.And I need to be able to send data between the views/activities.
Any suggestions how to do that? ViewFlipper or something else.

Better use activities inside the tab THREE and create three buttons which starts new activity.And you can use ViewFlipper inside these activities to change the views,or viewswticher.It depends on your needs.

You can override the onBackPressed in your activity to change the default behaviour of the back button
http://developer.android.com/reference/android/app/Activity.html#onBackPressed()

Related

How to implement horizontal view android studio

im trying to implement an android aplication when your activity, cointains 3 or more 'main windows' like in the image -> 'A'. 'B'.'C'. so how is posible make when you slide you touch screen change from A, to B, for example, i was thinkin in a horizontal view, and inside of each item use a relative layout, but im not sure, its my first time with this kind of problem, thanks.
Try using android ViewPager. Each ImageView would be inside a Fragment that would reside inside your Activity. Check out this example
Use Tabbed Activity template when you want to make this type of Activity. ViewPager, Adapter and tab layout will be automatically implemented for you. Just make small changes in your Adapter according to your needs and use one Fragment for one tab and you can create as many tabs as you want in an Activity.
If you want i will post an example of an Adapter as i just implemented an Activity with 3 tabs.
To get your basics strong on ViewPager, tab layout and Fragment sections adapter read out this link.

How to make tabs/sub-fragments inside a tab/fragment in Android

I have implemented an ActionBar with 3 tabs in an android app. I also used ViewPager to switch between different tabs. Every tab is defined in a fragment.
The last tab is called "Setting". I have two different settings. One is "Simple" setting, and the other one is "Advanced" setting. How can I implement these two different settings in the "Setting" tab. Should I make kind of sub-fragments or two new tabs inside the main tab which is "Setting" tab? Can I also for example create two buttons at the top, and switch between them? Or any better idea? Which solution is easier and more efficient. I'm a newbie in Android.
I want to make something like this:
Hope this help
Take SettingFragment as Host fragment
Place both buttons on top and ViewPager below buttons
Take SimpleFragment and AdvanceFragment as items in ViewPager

What is the best way to bind buttons and handle its states (something like RadioGroup)?

Remember when we used tabs, then pressing on one tab would turn that tab ON and all other tabs OFF.
Now, imagine 4 buttons in the middle of an Activity which represent tabs. Clicking on each buttons will turn that button to ON state, and all others to OFF state, and will accordingly load a fragment below these 4 buttons.
Right now, I have coded these buttons' states via foreach loop where I set the button states.
Is there a better way to do it? Something like RadioGroup and RadioButton where setting states is done automatically.
Take a look at android swipe view tab layout example! This code cycles among fragments (activities) based on which tab is pressed. Is this what you're looking for?
Please note that tabhost, another way of setting up tabs, is depricated.

Start activity inside ViewFlipper or a layout

I have a layout with tabs on top (added programmatically) and ViewFlipper under with 3 different views one of which contains a ListView. And I have 2 activities, one is the primary one that creates the tabs and one that dowloads some data and displays it in a new ListView. What I would like to do is start the second activity from the first one and display the data in the ListView that is inside ViewFlipper. Is it possible to do that?
What you are doing may be easier to achieve using fragments, or by putting the second activity into the ViewFlipper completely.
See the Android Developer site here for information on utilising fragments:

Android - How to change Activities within a TabActivity?

I currently have a TabActivity which has 4 tabs, within one of the tab's I want to be able to move forward and back between 4 different Activities.
However if I try to start a new Activity now it removes the TabActivty and starts a whole new Activity with no tab bars.
I have read about using view groups but that this is not best practice and also about using a view flipper but this doesn't seem to let me switch between different Activities only change the views within the Activity. I can't implement back functionality for exa,ple.
Can anyone point me in the right direction as to what I should be looking for as a solution to this?
EDIT:
Some more information:
Within the TabActivity my first screen will be a ListView that contains 4 rows, then selecting one of these will in turn load another ListView with 2 rows again within the TabActivity and then the 3rd screen will just contain some text depending on which option the user chose again within the Tab Activity.
Is a ViewFlipper the best solution here? It seems to me that it will require a lot of coding within one Activity if I use the ViewFlipper?
I have done something similar. I used the ViewFlipper to achieve this. You can override onBackPressed in your Activity so you can deal with moving back through your views.
There's a couple of ways of doing this but a simple way would be to just increment a counter in your Activity as you move to the next views, then in your onBackPressed method if counter != 0 just show the previous view, if counter == 0 call super.onBackPressed.
You can see in my video showing what the result could look like (ignore the bug being shown in the video).

Categories

Resources