How to use View Flipper to navigate between two activities - android

I have two activities and I want to navigate between these two activities with flipview?

view flipper is used only for navigation between views only not for activities.
From android 2.1 onwards there is method
Intent intent = new Intent(Fisrst.this, Second.class);
startActivity(intent);
overridePendingTransition(R.anim.slide_left, R.anim.slide_right);
so use like that. I think it will helpful for you.

Have a look at ViewPager

Related

Transition Animation From Fragment To Activity Android

In my application, I want to transit from Fragment to Activity.
For this purpose I am using following code for Animation,
Bundle bndlanimation =ActivityOptions.makeCustomAnimation(getActivity(), R.anim.slideinleft,R.anim.slideinright).toBundle();
startActivity(intentonboard,bndlanimation);
This works fine.
But What I want to do is that, I am moving from Fragment To Activity.
So I just want to apply the exit animation for Fragment only. Next Activity should be added behind the scene without animation.
So What Should I write in place of enter animation ?
I tried with 0 instead of R.anim.slideinright. But It effects on Exit animation.
Thanks
if you in fragment Layout and wanna to get intent to same activity you must use this...
Intent intent = new Intent(getActivity(),MainActivty.class);
startActivity(intent);
getActivity().overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
getActivity().overridePendingTransition(R.animator.slide_in_from_left, R.animator.slide_in_from_right);
Use getActivity() After startActivity(intent);
May this help you.

Android - Change Layout with an animation

This is my first week of Android development and I am having some troubles so please be patient with me.
This is really simple but all other answers weren't clear or detailed enough for me to apply it.
I am trying to switch from my "activity_main.xml" to a second .xml after a button click. I have already connected the button and put in setContentView(R.layout.view) and it works but I want it to animate. I want the view to come from the right and then the opposite when the user press back. I am doing this in eclipse if that helps.
Thanks in advance!
Assuming what you're after is a transition between two activities, here's what you're going to need to do:
Create a new Activity class. For this example, lets name it MySecondActivity.
In this new Activity class, make sure you're inflating the new layout xml.
In the original Activity class, open the new Activity with an Intent, then on the new activity, call the overridePendingTransition with the animation you want:
Code sample:
Intent intent = new Intent(this, MySecondActivity.class);
startActivity(intent);
getActivity().overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
In this example, I'm using Android pre-defined animations. You can create your own too, but I feel this might be enough for your needs.
Hope this helps.

How to implement a succession of activities within a single tab of a tabhost?

I have implemented a TabHost. In one tab I have Activity1, which calls Activity2 after a button click, which calls Activity3 after a button click, which calls Activity1 after a button click, etc.. No backstack functionality is required, just 1 --> 2 --> 3 --> 1, etc. All three activities have a separate layout file.
Everything works fine, except that after the first transition from 1 --> 2 the activities grab the entire screen and the tabs are invisble forever.
Question: how can I keep these three activities within the confinement of de tab area and the tabs visible? The problem has been recognized here many times before; the solution used to be ActivityGroups, but these are deprecated and Fragments are advised instead. I have seen many examples here, but nothing that could help me.
Can I keep my three activites (Activity1 extends Activity, etc)?
Should I add fragment tags to the layout files?
Do I need to work with transactions?
Should I work with one fragment class or three?
Can you please give me a few hints how I should go about? I woud already be helped if you tell which classes I need to use and of what type they are.
Thanks in advance.
It took me more than half a day, but finally found a solution that works. Unfortunately I am still stuck with deprecated issues (Activity Group and getLocalActivityManager().startActivity(..)).
Again I have a single tab under a TabHost and several activities, all operating within that tab. Navigation from one activity to the next occurs with a buttonclick. Solution:
all Activities operating within the tab need to extend ActivityGroup
All Activity classes need to have a button handler that links to the next activity like this:
public void onBtnClicked(View view) {
Intent intent = new Intent(view.getContext(), NextActivity.class);
replaceContentView("NextActivity", intent);
}
public void replaceContentView(String id, Intent newIntent) {
View view = getLocalActivityManager().startActivity(id, newIntent.
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
this.setContentView(view);
}
By this the tabs remain visible all the time, as desired.
Hope this helps someone.

Advantages of using Tabs over Intent

I just found out that we can use overridePendingTransition(0,0) to make a very simple transition between Layouts that override the current Android transition.
switch(v.getId()){
case R.id.btnCorner:
Intent i = new Intent(MainActivity.this, Settings.class);
startActivity(i);
overridePendingTransition(0,0);
break;
}
What is the advantage of using tabs over such a simple procedure?
My opinion is that tabs facilitate the transmission of variables between one "window screen" to another. Rather than passing the variable through intents.
Please note that I am not familiar with using Tabs and I hope someone can clarify the idea of using Tabs in an application.
Jonathan Hugh, nice questions really helpful for users , here i am going to give you brief description for both like : Intent take an example of any master-detail form where we want by using click on any ListView item row need to call another activity in this case i recommend you to use Intent because in same flow you require your result to be done, and other side, using tab it will give you more convenience to put your wishlist features in app using separate-separate tabs for all....
Tabs Like:-
private void setTabs()
{
addTab("Tab1", R.drawable.tab1, tab1.class);
addTab("Tab2", R.drawable.tab2, tab2.class);
addTab("Tab3", R.drawable.tab3, tab3.class);
addTab("Tab4", R.drawable.tab4, tab4.class);
}
What do you meen under tabs? There are several ways in Android to implement Tabs pattern. Some of them are better, other are not very good or deprecated. Not all of them are :
facilitate the transmission of variables
For example, using 3 different Activity, will significatelly increase amount of code, increase code connectivity and decrease code quality.
According to my point of view, in tabs, you can organize your work more systemically as compare to Intent.

android tabs - starting a new activity

There are 4 Tabs in a TabHost, let them be A, B, C, and D. Now each one is just an index page and clicking on any of them shows a different activity.
The problem is that I need to start another activity when the user selects something from the content displayed in the tab. The other activity should also be displayed in the parent tab itself. Is it possible? Or will I have to try something else?
Try this, found this solution in android cookbook,
http://androidcookbook.com/Recipe.seam;jsessionid=5424397F3130CE7769FF47DD67742911?recipeId=1693&recipeFrom=ViewTOC
Can't you change the contentView of your tab instead of starting a new Activity ?
Maybe I'm wrong but I think also that starting an activity in a tab isn't possible because the TabView is hosted in a activity and not the opposite (Tabview don't host an activity per Tab).
I think the common consensus is that it is best not to use individual Activities as tab content due to these limitations. See these questions and answers for pointers to alternatives:
Android: Why shouldn't I use activities inside tabs?
Android - Tabs, MapView, activities within tabs
To summarize the link that Rukmal Dias provided. Here's what you do:
Change your current Activity (that's in a tab) to derive from ActivityGroup
Create a new intent for the Activity you want to switch to
Copy/Paste and call this function in your current activity where "id" is the "android:id" for the layout of the new activity you want to switch to
public void replaceContentView(String id, Intent newIntent){
View view = getLocalActivityManager().startActivity(id,newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)) .getDecorView();
this.setContentView(view);}
Here's an example of how I make the call to switch views from my current Tabbed Activity:
public void switchToNextActivity(View view)
{
Intent myIntent = new Intent(getApplicationContext(), MyNextActivity.class);
replaceContentView("next_activity", myIntent);
}
It looses the view hierarchy. When you press the back button, in my case, the app closes.

Categories

Resources