Ye Myat Min
Ye Myat Min

Reputation: 1429

Using different activities for different views in a ViewFlipper

I am developing a Music Player and I have a view flipper to control all the artist view, album view, so on and so forth. What I am doing now is that I have list view in each view of the view flipper. However, I do not want to put all my codes inside one activity but rather, to have different activities for each view. Is that possible to implement?

Upvotes: 0

Views: 1773

Answers (2)

ahsteele
ahsteele

Reputation: 26504

If your goal is just to create the same user experience provided by ViewFlipper you'd be better off using overridePendingTransition(int enterAnim, int exitAnim) which has been available since API Level 5.

You'd call overridePendingTransition in whatever event was causing the activity to change. An example can be found within the Android SDK samples, but I provide one below to more fully answer your question.

First you must define your animations. Create a folder anim under res. Then define two transistions one in and one out.

in_right

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:fromXDelta="100%"
        android:toXDelta="0%"
        android:duration="600"/>
</set>

out_left

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:fromXDelta="0%"
        android:toXDelta="-100%"
        android:duration="600"/>
</set>

Then in the event which is starting the other activity you'd use these animations in your call to overridePendingTransition.

// this code snippet does not show wiring event to button
void buttonClicked() {
    startActivity(new Intent(this, HistoryListActivity_.class));
    overridePendingTransition(R.anim.in_right, R.anim.out_left);
}

Upvotes: 2

CommonsWare
CommonsWare

Reputation: 1006584

However, I do not want to put all my codes inside one activity but rather, to have different activities for each view.

Please don't do this. Not only is it not possible, but the other place where this is sorta supported (TabHost), it wastes RAM and CPU.

Upvotes: 1

Related Questions