Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8392331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:29:27+00:00 2026-06-09T19:29:27+00:00

I have a tabHost with 4 different intents in it. I am trying to

  • 0

I have a tabHost with 4 different intents in it. I am trying to see animation while traversing between tabs. the code I am using is partially works:

@Override
public void onTabChanged(String tabId) {
    // TODO Auto-generated method stub
    FrameLayout questionsLayout = (FrameLayout)tabHost.findViewById(android.R.id.tabcontent);
    questionsLayout.setAnimation(AnimationUtils.loadAnimation(tabHost.getContext(), R.anim.go_left_in));
}

however it only animates one animation which is an “inAnimation”, I also want to add an “outAnimation” too, how can I do that.

By the way, i am using this code to add each tabs:

intent = new Intent().setClass(this, Tabs.class);
intent.putExtra("questions", rawQ);
spec = tabHost.newTabSpec("english").setIndicator(getText(R.string.ingilizce),res.getDrawable(R.drawable.ic_tabs)).setContent(intent);
tabHost.addTab(spec);

Lastly, I am using api version 8.

Last edit, entire code:

public class Questions extends TabActivity implements OnTabChangeListener {

public static final String TAG = "Questions";
private String macAddr;
private String json;
private TabHost tabHost;
public void onCreate(Bundle savedInstanceState) {
    Log.v(TAG, "Activity State: onCreate() " + TAG);
    super.onCreate(savedInstanceState);

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        macAddr = extras.getString("macAddr");
        json = extras.getString("json");
    }




            // Make it fullscreen
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);




    // parsing json data
    Question[] rawQ = parseJson(json);

    if (rawQ==null) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(
                "Mac address could not found in database, please add it via control panel.")
                .setCancelable(false)
                .setNegativeButton("Okay",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog,
                                    int id) {
                                Intent i = new Intent(Questions.this, AnrdoinActivity.class);
                                 i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                 startActivity(i);

                            }
                        });

        AlertDialog alert = builder.create();
        alert.show();

    } else {

        setContentView(R.layout.questions);

        Resources res = getResources(); // Resource object to get Drawables
        tabHost = getTabHost(); // The activity TabHost
        TabHost.TabSpec spec; // Resusable TabSpec for each tab

        Intent intent; // Reusable Intent for each tab

        // Create an Intent to launch an Activity for the tab (to be reused)
        intent = new Intent().setClass(this, Tabs.class);
        intent.putExtra("questions", getLanguageQuestions(rawQ, 1));
        // Initialize a TabSpec for each tab and add it to the TabHost
        spec = tabHost
                .newTabSpec("kyrgyz")
                .setIndicator(getText(R.string.kirgizca),
                        res.getDrawable(R.drawable.ic_tabs))
                .setContent(intent);
        tabHost.addTab(spec);

        // Do the same for the other tabs
        intent = new Intent().setClass(this, Tabs.class);
        intent.putExtra("questions", getLanguageQuestions(rawQ, 2));

        spec = tabHost
                .newTabSpec("turkish")
                .setIndicator(getText(R.string.turkce),
                        res.getDrawable(R.drawable.ic_tabs))
                .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, Tabs.class);
        intent.putExtra("questions", getLanguageQuestions(rawQ, 3));

        spec = tabHost
                .newTabSpec("russian")
                .setIndicator(getText(R.string.rusca),
                        res.getDrawable(R.drawable.ic_tabs))
                .setContent(intent);
        tabHost.addTab(spec);

        intent = new Intent().setClass(this, Tabs.class);
        intent.putExtra("questions", getLanguageQuestions(rawQ, 4));

        spec = tabHost
                .newTabSpec("english")
                .setIndicator(getText(R.string.ingilizce),
                        res.getDrawable(R.drawable.ic_tabs))
                .setContent(intent);
        tabHost.addTab(spec);

        Log.v(TAG, 0+"");
        FrameLayout questionsLayout = (FrameLayout) tabHost.findViewById(android.R.id.tabcontent);
        Log.v(TAG, 1+""+questionsLayout.getId());

        Log.v(TAG, 2+"");
        tabHost.setCurrentTab(0);

        tabHost.setOnTabChangedListener(this);




    }


}
@Override
public void onTabChanged(String tabId) {
    // TODO Auto-generated method stub
    FrameLayout questionsLayout = (FrameLayout) tabHost.findViewById(android.R.id.tabcontent);      
    questionsLayout.setAnimation(AnimationUtils.loadAnimation(tabHost.getContext(), R.anim.go_left_in));
}

// Database related elements
private Question[] parseJson(String text) {
    JSONArray data = null;
    JSONObject groups = null;
    String[][] rawData = null;
    JSONArray[] questions = null;
    Question[] rawQ = null;
    try {
        data = new JSONArray(text);
        questions = new JSONArray[data.length() - 1];

        rawQ = new Question[questions.length];
        groups = data.getJSONObject(0);
        rawData = new String[2][groups.length()];
        Iterator it = groups.keys();
        int index = 0;

        while (it.hasNext()) {
            rawData[0][index] = (String) it.next();
            rawData[1][index] = groups.getString(rawData[0][index]);
            index++;
        }

        for (int i = 0; i < questions.length; i++) {
            questions[i] = data.getJSONArray(i + 1);

            String[] s = new String[6];
            for (int j = 0; j < s.length; j++) {
                s[j] = ((questions[i].getString(3 + j) == null) ? ("")
                        : (questions[i].getString(3 + j)));
            }
            rawQ[i] = new Question(questions[i].getInt(0),
                    questions[i].getInt(1), questions[i].getString(2), s);
        }

        Log.e(TAG, rawQ[1].getQuestion());
        return rawQ;
    } catch (JSONException e) {
        Log.e(ACTIVITY_SERVICE, e.toString());
        return null;
        // ctv.setText(data.toString());
    } catch (ArrayIndexOutOfBoundsException e) {
        Log.e(TAG, e.toString());
        return null;
    }

}
private Question[] getLanguageQuestions(Question[] Qs,int id){
    int count=0;
    for(Question q:Qs)
        count+=((q.getLanguageId()==id)?(1):(0));
    Question [] result = new Question[count];
    int index=0;
    for(Question q:Qs){
        if(q.getLanguageId()==id){
            result[index]=q;
            index++;
        }
    }
    return null;
}

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T19:29:28+00:00Added an answer on June 9, 2026 at 7:29 pm

    I’ve been looking around for ages to try and implement this, and actually wound up getting animations between different tabs (where my tabs are separate activities) by extending the TabHost slightly. In this particular implementation I’ve separated the animations so that it animates differently if you’re going to a tab to the left or right of the old one:

    public class MyAnimTabHost extends TabHost {
    
        public MyAnimTabHost(Context context) {
            super(context);
        }
    
        public MyAnimTabHost(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        @Override
        public void setCurrentTab(int index) {
    
            View currentView= this.getCurrentView();
    
            if (this.getCurrentTab()< index){
    
                if (currentView !=null){
                    currentView.startAnimation(AnimationUtils.loadAnimation(this.getContext(),R.anim.slide_out_to_left));
                }
    
                super.setCurrentTab(index);
    
                currentView= this.getCurrentView();
    
                if (currentView !=null){
                    currentView.startAnimation(AnimationUtils.loadAnimation(this.getContext(),R.anim.slide_in_from_right));
                }
            } else {
    
                if (currentView !=null){
                    currentView.startAnimation(AnimationUtils.loadAnimation(this.getContext(),R.anim.slide_out_to_right));
                }
    
                super.setCurrentTab(index);
    
                currentView= this.getCurrentView();
    
                if (currentView !=null){
                    currentView.startAnimation(AnimationUtils.loadAnimation(this.getContext(),R.anim.slide_in_from_left));
                }
    
            }
        }
    
    }
    

    Adding this as a new class, ADT will automatically add it to the list of custom views in the graphic xml editor, so you can just swap out the TabHost in the layout for this one, and all should be good (make sure you remember to actually implement your different anim xml files).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 4 tabs that I load using a TabHost and TabWidget using the
I have 2 different Layouts One is a TabHost which hosts different tabs where
I have created four tabs using tabhost, and placed four listviews in each like
I have a tabhost with two tabs. Each tab has his own activity. My
Using this sample : I have make my own Fragment that holds tabhost and
I have used a TabHost in my application with three tabs suppose A, B
Currently I have a TabHost implemented with 3 tabs each containing a separate activity.
I have problem with initializing TabHost. I need to have in View several Tabs
Guys, I have tried different samples using the list-view with fragments,In my application i
Newbee to Android development. I am developing a application, which have three different tabs.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.