moinudin
moinudin

Reputation: 138347

What's the standard way of swapping between UI elements in an activity in Android?

I have an activity that has several views. Most of the views will remain constant, but there's one area which has different views based on the actions of the user. In other words, we might start out with 3 buttons and then switch to a countdown timer when one is clicked. I don't think it makes sense to create different activities, since most of the UI (and logic) is shared.

What's the standard approach to this in Android? I'm really new to the platform.

Upvotes: 0

Views: 278

Answers (2)

Vipul Purohit
Vipul Purohit

Reputation: 9827

Use ViewFlipper or ViewSwitcher these are the best methods to switch between UI elements in Android. You can put animation to animate your UI switching.

User like this :

  // the viewflipper
    private ViewFlipper flipview;

    // set the flipper
    flipview = (ViewFlipper) findViewById(R.id.flipview);

  //To show next UI element just do like this
    flipview.ShowNext();

Upvotes: 1

reTs
reTs

Reputation: 1829

If only a small part of the layout is being swapped, basically I will play with View.Visibility. If it is set to GONE the view will be invisible and do not take up any space. Switch the visibility on button click events can do the trick.

http://developer.android.com/reference/android/view/View.html#attr_android:visibility

Upvotes: 1

Related Questions