0

Sorry for my bad english...

i made a tab bar activity in android application with this code:

TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
Intent intent = new Intent(this, Page2.class);
TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId); 

View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, tabHost.getTabWidget(), false);
TextView title = (TextView) tabIndicator.findViewById(R.id.title);
title.setText(labelId);
ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
icon.setImageResource(drawableId);

spec.setIndicator(tabIndicator);
spec.setContent(intent);
tabHost.addTab(spec);

With this code i can create any tab i want and all tabs call an activity. All works fine, but there is a way to call a function when click (or tap) on a tab instead of call an activity?

1 Answers1

0

you can use a onclick listener for Tabhost

you will have 3 ids initialize them and use onclick for the tab you want

    Tab.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

                         yourfunctionname(); //call your functions 

        }
    });
Metalhead1247
  • 1,978
  • 1
  • 17
  • 28