1

I want one of my tabs in my TabLayout to essentially work as a Button where when pressed the default calculator is opened instead of a tab with an Activity in it. How would I go about doing this? Below is know it would be done with a Button.

Button calcButton = (Button) findViewById(R.id.CalcButton);
calcButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent calcIntent = new Intent();
            calcIntent.setClassName("com.android.calculator2",
                    "com.android.calculator2.Calculator");
            startActivity(calcIntent);
        }
    });

edit: I want the calculator to open full screen not within the tab view.

1 Answer 1

2

You could implement a onTabChangeListener and when ever the user goes to that tab, you could just launch the intent you want to start.

mTabHost.setOnTabChangedListener(new OnTabChangeListener(){
@Override
public void onTabChanged(String tabId) {
    if(TAB_BUTTON_TAG.equals(tabId)) // TAB_BUTTON_TAG is the tag associated with your tab
    {
        Intent calcIntent = new Intent();
        calcIntent.setClassName("com.android.calculator2", "com.android.calculator2.Calculator");
        startActivity(calcIntent);

    }

}});
1
  • 1
    Worked great, I have a new tool in my arsenal. Thank you! Nov 11, 2012 at 21:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.